?
Solved

Submit a Non-Named Variable to a URL via a GET

Posted on 2005-04-05
10
Medium Priority
?
241 Views
Last Modified: 2010-04-09
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?
0
Comment
Question by:eeyore7250
9 Comments
 
LVL 6

Expert Comment

by:Leviter
ID: 13714210
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
 
LVL 4

Author Comment

by:eeyore7250
ID: 13714250
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
 
LVL 6

Expert Comment

by:Leviter
ID: 13714269
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:eeyore7250
ID: 13714324
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
 
LVL 6

Expert Comment

by:Leviter
ID: 13714384
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
 
LVL 4

Author Comment

by:eeyore7250
ID: 13722449
Ok, now that doesnt submit the other form variables. (Of which there could be any number of)
0
 
LVL 4

Author Comment

by:eeyore7250
ID: 13956159
Yes, please delete
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 14770860
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
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 15591313
PAQed with no points refunded (of 100)



Computer101
EE Admin
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question