Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Why does one URL direct work and the other not?

    I read a beginners book on js and now I'm working through a cookbook style book to get a hang of things, I came across an example for redirecting URLs in the book that didn't work:

    Code:
    <form>
    <input type="text" name="url">
    <input type="button" value="Go" onClick="location.href=this.form.url.value">
    </form>
    After searching on the net I found another that works perfectly but
    I don't understand why the one in the book doesn't work.

    works:
    Code:
    <form name="openlocation">
    <input type="text" name="href">
    <input type="button" value="Go" onClick="location.href=document.openlocation.href.value;; ">
    </form>
    I tried replacing the url with href and other tweaks, is it that you cant use ".this" here, making it necesary to name the form?

    Any explanation help would be apreciated.

    Thanks in advance!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,316
    Thanks
    203
    Thanked 2,566 Times in 2,544 Posts
    Why do you think that it does not work?

    Code:
    <form>
    <input type="text" name="url" value = "http://www.google.com">
    <input type="button" value="Go" onClick="location.href=this.form.url.value">
    </form>

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #3
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Philip,

    I tried substituting url for href in the name and the onclick, and I also tried adding "document." in the onclick.

    I think it's because the form needs a name, then needs to be referenced, but I don't understand why you cant just use ".this"

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,316
    Thanks
    203
    Thanked 2,566 Times in 2,544 Posts
    See Post#2.

    Why do you think that it does not work?

    Code:
    <form>
    <input type="text" name="url" value = "http://www.google.com">
    <input type="button" value="Go" onClick="location.href=this.form.url.value">
    </form>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •