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

How do I create a form and use the value to pass to a base URL? 2

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
I am trying to create a HTML form and pass the value of the search field to append it to the URL.

For example:

Search: 123456

Press "Go" and the destination URL becomes
I know how the basic forms work, but I can't figure out how to append the base URL with the variable from the input.

<HTML>
<HEAD>
<SCRIPT type="javascript">
function goToPage(var url = '')
{
var initial = "
window.location(initial+url);
}
</SCRIPT>
<TITLE>Test</TITLE>
<BASE HREF="</HEAD>
<BODY>
<P>
<FORM name="something" action="#">
Search
<INPUT type="text" name="url" value="" onSubmit="goToPage(this.value)">
<INPUT type="submit" value="GO">
</FORM>
</BODY>
</HTML>

Any assistance would be greatly appreciated.

Thanks,

John
 
Don't submit, have Js intercept the form, and use the value to create the URL:

Code:
[COLOR=#990000]<[/color]FORM name[COLOR=#990000]=[/color][COLOR=#FF0000]"something"[/color] action[COLOR=#990000]=[/color][COLOR=#FF0000]"#"[/color] onsubmit[COLOR=#990000]=[/color][COLOR=#FF0000]"return goToPage(this);"[/color][COLOR=#990000]>[/color]
Search
[COLOR=#990000]<[/color]INPUT type[COLOR=#990000]=[/color][COLOR=#FF0000]"text"[/color] name[COLOR=#990000]=[/color][COLOR=#FF0000]"urlInput"[/color] value[COLOR=#990000]=[/color][COLOR=#FF0000]""[/color] onSubmit[COLOR=#990000]=[/color][COLOR=#FF0000]"goToPage(this.value)"[/color][COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]INPUT type[COLOR=#990000]=[/color][COLOR=#FF0000]"submit"[/color] value[COLOR=#990000]=[/color][COLOR=#FF0000]"GO"[/color][COLOR=#990000]>[/color]
[COLOR=#990000]</[/color]FORM[COLOR=#990000]>[/color]

Code:
[b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]goToPage[/color][/b][COLOR=#990000]([/color]formObj[COLOR=#990000])[/color]
[COLOR=#FF0000]{[/color]
[b][COLOR=#0000FF]var[/color][/b] initial [COLOR=#990000]=[/color] [COLOR=#FF0000]"[URL unfurl="true"]http://www.example.com/page1/"[/URL][/color][COLOR=#990000];[/color]
[b][COLOR=#0000FF]var[/color][/b] url [COLOR=#990000]=[/color] formObj[COLOR=#990000].[/color]urlInput[COLOR=#990000].[/color]value[COLOR=#990000];[/color]

window[COLOR=#990000].[/color][b][COLOR=#000000]location[/color][/b][COLOR=#990000]([/color]initial[COLOR=#990000]+[/color]url[COLOR=#990000]);[/color]
[b][COLOR=#0000FF]return[/color][/b] [b][COLOR=#0000FF]false[/color][/b][COLOR=#990000];[/color]
[COLOR=#FF0000]}[/color]

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

Web & Tech
 
Hi vacunita,

Thank you for your response. I tried your suggestion and it seems to do something similar to what I tried; It appends ?urlInput=$INPUT# to the URL instead of going to the correct destionation URL where $INPUT is the data entered into the form.

Any thoughts?

Thanks,

John
 
The error is in the usage of window.location. Copied from your code, and forgot to correct it. It should be:

Code:
function goToPage(formObj)
{
var initial = "[URL unfurl="true"]http://localhost/showGet.php";[/URL]
var url = formObj.urlInput.value;

[red]window.location = initial+url[/red];
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.

Web & Tech
 
Hi Vacunita,

This is what I have:

Code:
<HTML>

<FORM name="something" action="#" onsubmit="return goToPage(this);">
Service Tag
<INPUT type="text" name="urlInput" value="" onSubmit="goToPage(this.value)">
<INPUT type="submit" value="GO">
</FORM> 

<SCRIPT type="javascript">
function goToPage(formObj)
{
var initial = "[URL unfurl="true"]http://www.dell.com/support/troubleshooting/us/en/04/Servicetag/";[/URL]
var url = formObj.urlInput.value;

window.location = initial+url;
return false;
} 

</HTML>

Am I doing something wrong?

John
 
Hi

John said:
Am I doing something wrong?
[ul]
[li]Invalid value for [tt]script[/tt] tag's [tt]type[/tt] attribute. Use "text/javascript" instead.[/li]
[li]Invalid [tt]script[/tt] section. Add a close [tt]script[/tt] tag.[/li]
[/ul]

Feherke.
[link feherke.github.com/][/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top