|
-
Aug 25th, 2001, 08:44 PM
#1
Thread Starter
Fanatic Member
Setting window location with a form
Code:
<html>
<head>
<script>
function validURL(url)
{
if ((url == "") || (url == "http://"))
return false;
return true;
}
function submitIt(form)
{
if (validURL(form.urlname.value))
window.location = form.urlname.value
else
{
alert("Please type a URL");
return false;
}
}
</script>
</head>
<body>
<form onSubmit="return submitIt(this)" name="form1" method="post">
URL: <input name="urlname" type="text" value="http://">
<input type="submit" value="Go">
</form>
</body>
</html>
This code doesn't work, not sure why. What's wrong?
Alcohol & calculus don't mix.
Never drink & derive.
-
Aug 25th, 2001, 09:53 PM
#2
try putting the
Code:
<input type="submit" value="Go" onSubmit="return submitIt(this)">
or you can take out "this" and "form" and see what you get.
-
Aug 25th, 2001, 09:58 PM
#3
PowerPoster
i already tried that and it doesn't work...Man, i am stumped on this one. It has to be in the area of the window.location, because the function is getting the string ok. Man, i have done this before with selectboxes, and it worked, but it won't work now!
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Aug 25th, 2001, 10:07 PM
#4
what does it do exactly, it looks like it checks for an input and sends you to the page?
try window.open instead of window.location
actually it looks like it is here where it says
return false;
return true;
forget something, like else??
-
Aug 25th, 2001, 10:10 PM
#5
PowerPoster
i tried taking that out and it still doesn't work
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Aug 25th, 2001, 10:10 PM
#6
Thread Starter
Fanatic Member
No, tried the 'else.' What it is supposed to do is you type a URL in the text box and click Go and it takes you to that page.
Alcohol & calculus don't mix.
Never drink & derive.
-
Aug 25th, 2001, 10:29 PM
#7
Fanatic Member
try this, it works for me:
Code:
<html>
<head>
<title></title>
<script>
function validURL(url)
{
if ((url == "") || (url == "http://"))
return false;
return true;
}
function submitIt(form)
{
if (validURL(form.urlname.value))
window.location.href = form.urlname.value;
else
{
alert("Please type a URL");
}
}
</script>
</head>
<body>
<form name="form1">
URL: <input name="urlname" type="text" value="http://">
<input type="button" value="Go" ONCLICK = "submitIt(document.forms['form1']);">
</form>
</body>
</html>
-
Aug 25th, 2001, 10:48 PM
#8
Thread Starter
Fanatic Member
Cool, that works great, but I have one more question: How can I do the same thing when the user presses Enter?
Alcohol & calculus don't mix.
Never drink & derive.
-
Aug 25th, 2001, 11:18 PM
#9
the only thing I have to say to Chris's satement is that "button" is an IE only thing. NS doesn't see it.
-
Aug 25th, 2001, 11:47 PM
#10
PowerPoster
instead of button change it to submit, it should work then.
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Aug 25th, 2001, 11:58 PM
#11
onClick duhhhh I should have thougth of that
-
Aug 25th, 2001, 11:59 PM
#12
Thread Starter
Fanatic Member
Originally posted by scoutt
the only thing I have to say to Chris's satement is that "button" is an IE only thing. NS doesn't see it.
Isn't that the <button> tag, not the "button" attribute of the <input> tag?
Alcohol & calculus don't mix.
Never drink & derive.
-
Aug 26th, 2001, 12:02 AM
#13
I think it is the button attribute in the input tag. try it and see.
-
Aug 26th, 2001, 12:07 AM
#14
PowerPoster
<input type=button> will work in NS
scoutt you are thinking of the <button> tag i think
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Aug 26th, 2001, 12:14 AM
#15
might be.. can't remeber what I read, it all blends together the more I read..
-
Aug 26th, 2001, 01:00 PM
#16
Fanatic Member
<input TYPE = "button">
Works for all flavors...
<button> is IE specific.
If I post a solution in which I think it's IE-specific I usually note it.
-
Aug 26th, 2001, 01:03 PM
#17
thanks chris, I was mixed up.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|