Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

POST DATA

Status
Not open for further replies.

jasonhuibers

Programmer
Sep 12, 2005
290
CA
My code below simply opens a window. How can I modify the code below to post the data by submitting the form rather than just opening the window?



<form name="Form1" method="POST">
<SCRIPT LANGUAGE="JavaScript">

var w=500; /* popup window width*/
var h=440; /* popup window height*/

var l=(screen.width-w)/2; /*this centers horizontally*/
var t=(screen.height-h)/2; /*this centers vertically*/

var url="Test111.asp";

var features="left="+l+",top="+t+",width="+w+",height="+h+",scrollbars=auto";

function popItUp() {
window.open(url,"",features);

}

</script>


<select name="cboEvent" onchange="popItUp()" align=center width="200" size="12" style="font-family: courier new;WIDTH: 565px; HEIGHT: 98px;font-size: x-small">

<option value="Item1">
</select>
 
Open a Window, give it a name, and then direct the form submission to it.

Code:
<script>
function popItUp(){
window.open(url,"[red]mywindow[/red]",features);
}
</script>


<form action="Test111.asp" method=POST target="[red]mywindow[/red]" onSubmit="popItUp(); return true;">
...



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
What about the variable url - this will not call the page in Action...

window.open(url,"mywindow",features);

should I remove it?
 
You can change it to nothing, just an empty string if you want to.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Here is my code it does not seem to be submitting the form nor calling the page in the action="testMain.asp"

A blank window appears "about:blank"


<form name="Form1" method="POST" action="testMain.asp" target="newWin" onSubmit="popItUp(); return true;">

<SCRIPT LANGUAGE="JavaScript">

var w=500; /* popup window width*/
var h=440; /* popup window height*/

var l=(screen.width-w)/2; /*this centers horizontally*/
var t=(screen.height-h)/2; /*this centers vertically*/

var url="";

var features="left="+l+",top="+t+",width="+w+",height="+h+",scrollbars=auto";

function popItUp() {
window.open(url,"newWin",features);

}
 
Hard to say with only part of the form. How are you submitting the form?

Where's the submit button?

What is the form supposed to submit? Any input values?

Your original code had test111.asp your new one has testMain.asp which one is correct?

What is your testMain.asp supposed to do with the information? Is it supposed to show anything?








----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Yes, you are right - I actually do not have a submit button. I want to submit hidden values below to TestMain.asp. There I will use a Response.write request.form("txtHiddenDate"), etc....

<input name="txtHiddenDate" visible="" value="<%=strDate%>">
<input name="txtHiddenCity" visible="" value="<%=strCity%>">


How can I submit the form. The code is exactly as posted except that I am calling testMain.asp instead of test111.asp

 
The question would be 'when' you want to submit them?

You can use the forms own submit function to initiate the submission, but you'd need to know when you want to do this.

Likely if this is meant to generate information to display when the user selects something then you would initiate the submission with the users action.

Say he clicks somewhere, or changes the value of something.

For example:

Code:
<a href="#"  onClick="document.Form1.Submit(); return false;">Click here to Submit the form</a>

The form would be submitted when the user clicks the link.
It could be when the user selects an option form a drop down, or even alters the value of a textbox.


By the way, if that's the exact code, you are also missing a closing </form> tag. Which may be impeding the submission of the form.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
The form should be submitted when the user selects an item from the list on the OnChange in the Select...

onchange="popItUp()"
 
onChange="document.Form1.submit();"

The form submission triggers the popItUp() function.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
This opens a window which is correct but the "features" line is ignored. What I like about this is the new window opens in the size I am looking for. How Can I do this taking the "features" line into consideration??

<form name="Form1" method="POST" action="testMain.asp" target="newWin" onSubmit="popItUp(); return true;">

<SCRIPT LANGUAGE="JavaScript">

var w=500; /* popup window width*/
var h=440; /* popup window height*/

var l=(screen.width-w)/2; /*this centers horizontally*/
var t=(screen.height-h)/2; /*this centers vertically*/

var url="";

var features="left="+l+",top="+t+",width="+w+",height="+h+",scrollbars=auto";

function popItUp() {
window.open(url,"newWin",features);

}



<select name="cboEvent" onchange="document.Form1.submit();" align=center width="200" size="12" style="font-family: courier new;WIDTH: 565px; HEIGHT: 98px;font-size: x-small">

<% Do While Not drs.EOF %>
<option value="<% = drs("RecordNum") %>">
<%

drs.MoveNext
Loop
conn2.close
set conn2 = nothing %>
</select>

</form>
 
Ahh yes, my mistake. We'll need to change it around a bit.

Code:
<form name="Form1" method="POST" action="testMain.asp" target="newWin" return true;">

<SCRIPT LANGUAGE="JavaScript">

  var w=500;                        /* popup window width*/
  var h=440;                        /* popup window height*/

  var l=(screen.width-w)/2;         /*this centers horizontally*/
  var t=(screen.height-h)/2;        /*this centers vertically*/

 var url="";

  var features="left="+l+",top="+t+",width="+w+",height="+h+",scrollbars=auto";

function popItUp() {
        window.open(url,"newWin",features);
[red]        document.Form1.Submit();        [/red]]
 }

[blue]</script>[/blue]

<select name="cboEvent" onchange="[red]popItUp();[/red]" align=center width="200" size="12" style="font-family: courier new;WIDTH: 565px; HEIGHT: 98px;font-size: x-small">

<%    Do While Not drs.EOF %>
<option value="<% = drs("RecordNum") %>">
<%

drs.MoveNext
Loop
    conn2.close
    set conn2 = nothing %>
</select>

</form>

That should work. We use the same function popItUp to create the new window with the appropriate features, and then it submits the form.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I tried your code and it never submits the form. I still get a window (with the correct dimensions) but it is a blank window not the page indicated in the form action tag.
 
[0] url is not defined.
[1] there is a deliquent closing bracket.
[2] Submit() is commonly known as submit(), though it works.
[tt]
function popItUp() {
window.open([red]document.Form1.action[/red],"newWin",features);
document.Form1.submit(); [highlight] [/highlight]
}
[/tt]
[3] You may consider passing the form itself to the popItUp(), like this.
[3.1]
[tt]<select name="cboEvent" onchange="popItUp([blue]this.form[/blue]);" align="center" width="200" size="12" style="font-family: courier new;WIDTH: 565px; HEIGHT: 98px;font-size: x-small">[/tt]
[3.2][tt]
function popItUp(oform) {
window.open([red]oform.action[/red],"newWin",features);
oform.submit();
}[/tt]
[4] Text is not scripted, maybe just a miss-out.
[5] I am doubtful align="center" is effective cross-browser. But it is not on the topic.
 
This did the trick...

function popItUp() {
window.open(document.Form1.action,"newWin",features);
document.Form1.Submit();
}
 
[0] url is not defined.
Yes it is, its just empty. since I wasn't opening a url in the window.open function I just set it as empty. The action from the form would take care of opening the page there.
[1] there is a deliquent closing bracket.

Oops missed that one.
[2] Submit() is commonly known as submit(), though it works.

function popItUp() {
window.open(document.Form1.action,"newWin",features);
document.Form1.submit();
}
so what's the problem?
[3] You may consider passing the form itself to the popItUp(), like this.
[3.1]


<select name="cboEvent" onchange="popItUp(this.form);" align="center" width="200" size="12" style="font-family: courier new;WIDTH: 565px; HEIGHT: 98px;font-size: x-small">
[3.2]
function popItUp(oform) {
window.open(oform.action,"newWin",features);
oform.submit();
}

what for, you aren't using the form for anything other than submitting it.
[4] Text is not scripted, maybe just a miss-out.
Don't know what this refers to.
[5] I am doubtful align="center" is effective cross-browser. But it is not on the topic.
Correct, A CSS approach would have been better, but its irrelevant to the subject at hand.

By the way, I did test the code myself before submitting it and it worked for me as is. Obviously the extraneous "]" was a typo. but other than that it worked.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I don't get it. For what reason it is so defensive?
 
Not defensive just explaining. I do agree with most of what you said though.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
>Submit() is commonly known as submit(), though it works.
>>so what's the problem?
The only problem is that I don't find it in html5 recommendation and normally case-sensitivity is the 2nd nature.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top