Results 1 to 17 of 17

Thread: Setting window location with a form

  1. #1

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772

    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.

  2. #2
    scoutt
    Guest
    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.

  3. #3
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    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

  4. #4
    scoutt
    Guest
    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??

  5. #5
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    i tried taking that out and it still doesn't work

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  6. #6

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    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.

  7. #7
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    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>
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  8. #8

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    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.

  9. #9
    scoutt
    Guest
    the only thing I have to say to Chris's satement is that "button" is an IE only thing. NS doesn't see it.

  10. #10
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    instead of button change it to submit, it should work then.

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  11. #11
    scoutt
    Guest
    onClick duhhhh I should have thougth of that

  12. #12

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    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.

  13. #13
    scoutt
    Guest
    I think it is the button attribute in the input tag. try it and see.

  14. #14
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    <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

  15. #15
    scoutt
    Guest
    might be.. can't remeber what I read, it all blends together the more I read..

  16. #16
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    <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.
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  17. #17
    scoutt
    Guest
    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
  •  



Click Here to Expand Forum to Full Width