Forum Moderators: open

Message Too Old, No Replies

Variable links from input

input a variable into a form, adjusting and activating a link

         

Nicholson

11:04 pm on Jun 30, 2006 (gmt 0)

10+ Year Member



I am trying to find a way (google search found nothing)to have a text field on my website, so that the input will be inserted into a hyperlink, then activated...
For example: text input="forum", submit button to activate hyperlink=http://www.website.com/folder/forum...

this is my JS code so far -

<script language='javascript'>
function change_url() {
document.location = "http://www.website.com/folder/"+form1.text1.value;
}

<form name='form1' onSubmit='change_url();return false();' target="new window">
<input type='text' name='text1' />
<input type='submit' value='Go to URL' onClick='change_url()' />
</form>
</script>

My problem is that when i type in the variable into to field then submit, the original page goes to that variable website, while the new window opened is my webpage with the address of "file:///C:/index.html?text1=kboi" (kboi being the variable entered) instead of the usual address of C:\index.html

Bernard Marx

11:50 pm on Jun 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Before running any tests, I'd say:

1) return false();

false is a primitive value, not a function. The brackets will cause an error.

2) Avoid whitespace in window names. It can cause trouble in some browsers.

3) The fn call, change_url(), appears TWICE.

Is this the behaviour you're after?

<html><head><title>TEST</title>

<script type='text/javascript'>

function change_action(form)
{
form.action = "http://www.example.com/folder/"
+ form.text1.value+".htm";
/*test*/ alert(form.action);
}

</script>

</head>
<body>
<form target="newWin"
onsubmit='change_action(this)'>
<input type='text' name='text1'>
<input type='submit' value='Go to URL'>
</form>
</body>
</html>

Nicholson

4:00 am on Jul 1, 2006 (gmt 0)

10+ Year Member



That is what I am after, thank you so much. There is only one thing, I am not sure if it is normal or not. What I am after is for a new window to pop up with the following website "http://www.example.com/folder/kboi" (kboi being my variable) and it works perfectly, goes to the desired website and all, except after the address is "?text1=kboi" soo... "http://www.example.com/folder/kboi?text1=kboi"

Is that normal?

Bernard Marx

8:39 am on Jul 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is normal. The default method is GET, which appends the form data to a query string in the URL. If you use method="post" the data will be sent as part of the request header.

It depends on how you are handling the form data.
- If at all.

Nicholson

8:21 pm on Jul 1, 2006 (gmt 0)

10+ Year Member



Alright, thank you so much