eeyore7250
asked on
Submit a Non-Named Variable to a URL via a GET
I need to get a varable into the URL after a submit of a GET. The problem is, I don't want this variable to be named. I have tried the following two methos without success:
1. <form method='get'><input type='hidden' value='abc'></form>
2. <form method='get'><input type='hidden' value='abc' name=''></form>
The reason I need to do this is it's submitting to a third party web application and the first input parameter for the web application is unnamed. So my URL should look something like this:
http://localhost/webapp?abc
Any ideas?
1. <form method='get'><input type='hidden' value='abc'></form>
2. <form method='get'><input type='hidden' value='abc' name=''></form>
The reason I need to do this is it's submitting to a third party web application and the first input parameter for the web application is unnamed. So my URL should look something like this:
http://localhost/webapp?abc
Any ideas?
ASKER
Thanks for your response, however it doesnt achieve the required result. This is the resulting URL of your test:
http://localhost/webapp?myField=abc
Its the same with a get as if I had specified the action myself like this (apart from I wouldn't have an unwanted "myField"variable in the URL):
<form method="get" action='http://localhost/webapp?abc'>
BTW: That would work if the methos was post!
http://localhost/webapp?myField=abc
Its the same with a get as if I had specified the action myself like this (apart from I wouldn't have an unwanted "myField"variable in the URL):
<form method="get" action='http://localhost/webapp?abc'>
BTW: That would work if the methos was post!
Whoops....
I see my mistake... There still is the hidden field inside the form. When the form gets submitted... it also sends the field.
Is it possible to write the value of the field into a javascript variable?
<script language="JavaScript">
<!--
var hiddenField = "abc";
//-->
</script>
<form name="myForm" method="get">
<input type="submit" onClick="document.myForm.a ction='web app?' + hiddenField;">
</form>
Otherwise you could move the hidden field into another form that you won't submit, but where you do get your value from.... Like so:
<form name="hiddenForm">
<input type="hidden" name="myField">
</form>
<form name="myForm" method="get">
<input type="submit" onClick="document.myForm.a ction='web app?' + document.hiddenForm.myFiel d.value; myForm.submit();">
</form>
I see my mistake... There still is the hidden field inside the form. When the form gets submitted... it also sends the field.
Is it possible to write the value of the field into a javascript variable?
<script language="JavaScript">
<!--
var hiddenField = "abc";
//-->
</script>
<form name="myForm" method="get">
<input type="submit" onClick="document.myForm.a
</form>
Otherwise you could move the hidden field into another form that you won't submit, but where you do get your value from.... Like so:
<form name="hiddenForm">
<input type="hidden" name="myField">
</form>
<form name="myForm" method="get">
<input type="submit" onClick="document.myForm.a
</form>
ASKER
Thanks again for your quick response. Your method is still adding the variable to the Action URL. Variables in the Action URL are removed when you submit a form via GET. They only stay if it is a POST.
eeyore7250,
This code does do the trick.... I checked it with the logfiles to see what is submitted... and you can clearly see it on the URL...
<html>
<body>
<script language="JavaScript">
<!--
var hiddenField = "abc";
//-->
</script>
<form name="myForm">
<input type="button" onClick="document.location .href='tes t.html?' + hiddenField;">
</form>
</body>
</html>
This code does do the trick.... I checked it with the logfiles to see what is submitted... and you can clearly see it on the URL...
<html>
<body>
<script language="JavaScript">
<!--
var hiddenField = "abc";
//-->
</script>
<form name="myForm">
<input type="button" onClick="document.location
</form>
</body>
</html>
ASKER
Ok, now that doesnt submit the other form variables. (Of which there could be any number of)
ASKER
Yes, please delete
If you had told us you wanted more than one field PLUS the javascript var then we could have told you this in case of GET:
<form action ="http://www.thirdparty.com/someaction" "
onSubmit="myVar='abc';
loc = this.action+'?'+myVar;
for (i=0;i<this.elements.lengt h;i++) {
loc += '&'+this.elements[i].name+ '='+escape (this.elem ents[i].va lue);
}
location=loc;
return false">
<input type="text" name="field1" value="">
<input type="text" name="field2" value="">
<input type="text" name="field3" value="">
<input type="text" name="field4" value="">
<input type="submit">
</form>
<form action ="http://www.thirdparty.com/someaction" "
onSubmit="myVar='abc';
loc = this.action+'?'+myVar;
for (i=0;i<this.elements.lengt
loc += '&'+this.elements[i].name+
}
location=loc;
return false">
<input type="text" name="field1" value="">
<input type="text" name="field2" value="">
<input type="text" name="field3" value="">
<input type="text" name="field4" value="">
<input type="submit">
</form>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your form could look something like this:
<form name="myForm" method="get">
<input type="hidden" name="myField">
<input type="submit" onClick="document.myForm.a
</form>