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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URL plus variable from input box

Status
Not open for further replies.

cbsarge

IS-IT--Management
Jun 20, 2001
219
0
0
US
I can't seem to get this working so I was hoping someone could help. I'm trying to make a simple page with a text box asking for input and haveing the input variable added to the end of a URL. My non-working html is below.
Thanks!

<HTML>
<HEAD>
<TITLE>Test Page</TITLE>
</HEAD>
<BODY>
<H3>Test Page</H3><HR>
<form>
ID number: <input type="text" name="input" /><br />
</form>
<FORM>
<INPUT TYPE=BUTTON onClick="location.href='[id_number]=input'" VALUE="Click Here" >
</FORM>
</BODY>
</HTML>

[!]The AutoSavers![/!] [2thumbsup]
 
The easy, and only HTML based way would be to use the form correctly; including both the button and the text box in the same form, and set its method to GET.

Code:
<form action="'[URL unfurl="true"]http://www.somepage.com"[/URL] method=[red]GET[/red]>
<input type="text" name="input" [red]id="theTextbox"[/red]/>
<INPUT TYPE=submit name="sub" value="Click Here">
</form>

Nothing else is needed, as that will append the value to the URL automatically.

If you must use javascript (it technically falls outside the scope of this forum), you would need to actually access the textbox and append the value to the url.



----------------------------------
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.

Behind the Web, Tips and Tricks for Web Development.
 
Don't quite understand what you mean, but if its that you need to preserve the other url parameters you can use hidden fields:

Code:
<form action="'[URL unfurl="true"]http://www.somepage.com"[/URL] method=GET>
<input type="hidden" name="[red]first_page[/red]" value="[red]screws[/red]">
<input type="hidden" name="[red]id_number[/red]" value="[red][/red]">


<input type="text" name="input" id="theTextbox"/>
<INPUT TYPE=submit name="sub" value="Click Here">
</form>


or in fact resort to Javascript.


Code:
<input type=button value="Click Here" onClick="location.href='[URL unfurl="true"]http://www.somepage.com/?first_page=screws&;id_number=6[/URL][red]&input[/red]'+ document.getElementById(\'theTextbox\').value; return false;">

----------------------------------
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.

Behind the Web, Tips and Tricks for Web Development.
 
Sorry I messed up the quotes in the JS.

Also make sure the textbox has an ID.

Code:
<input type=button value="Click Here" onClick="location.href='[URL unfurl="true"]http://www.somepage.com/?first_page=screws&;id_number=6&input[/URL][red]=[/red]'+ document.getElementById([red]'[/red]theTextbox[red]'[/red]).value; return false;">

----------------------------------
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.

Behind the Web, Tips and Tricks for Web Development.
 
I'd strongly recommend you follow vacunita's first suggestion and use hidden fields, rather than introduce an unnecessary javascript dependency into your code.

All you need to do to get it to work is remove the stray ' that he had in the beginning of his form's [tt]action[/tt] attribute:
Code:
<form action="[URL unfurl="true"]http://www.somepage.com"[/URL] method=GET>
<input type="hidden" name="first_page" value="screws">
<input type="hidden" name="id_number" value="">


<input type="text" name="input" id="theTextbox"/>
<INPUT TYPE=submit name="sub" value="Click Here">
</form>

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
The page I'm trying to create is pointing at someone else's page. There is actually another part of the URL that might be making this not work correctly. After screws is [copper]. The resulting URL is supposed to look like this:

Code:
[URL unfurl="true"]http://somepage.com/?first_page=screws&id_number[/URL][copper]=12345

what my link to it is resulting in is:

Code:
[URL unfurl="true"]http://somepage.com/?first_page=screws&id_number=&input=12345&sub=Click+Here[/URL]

[!]The AutoSavers![/!] [2thumbsup]
 
Not to get too far off the subject, but how will a user of your page know what numbers to enter?

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top