Forum Moderators: open
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
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>
Is that normal?