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?
LVL 4
eeyore7250Asked:
Who is Participating?
 
Computer101Commented:
PAQed with no points refunded (of 100)



Computer101
EE Admin
0
 
LeviterCommented:
You can change the action of the form manually by using javascript.

Your form could look something like this:

<form name="myForm" method="get">
    <input type="hidden" name="myField">
    <input type="submit" onClick="document.myForm.action='webapp?' + document.myForm.myField.value;">
</form>
0
 
eeyore7250Author Commented:
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!
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
LeviterCommented:
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.action='webapp?' + 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.action='webapp?' + document.hiddenForm.myField.value; myForm.submit();">
</form>
0
 
eeyore7250Author Commented:
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.
0
 
LeviterCommented:
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='test.html?' + hiddenField;">
</form>

</body>
</html>


0
 
eeyore7250Author Commented:
Ok, now that doesnt submit the other form variables. (Of which there could be any number of)
0
 
eeyore7250Author Commented:
Yes, please delete
0
 
Michel PlungjanIT ExpertCommented:
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.length;i++) {
  loc += '&'+this.elements[i].name+'='+escape(this.elements[i].value);
}
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>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.