SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: location.href

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    location.href

    At my wits end, copied a form and changed some text and stuff and have no idea why this isn't working. At the bottom I have a submit button and a cancel button. The cancel button takes you to another page. For some reason, this cancel button does nothing unless I put the </form> tag above it, right after the submit button. Why does it work on one page and not another?

    Code:
    doesn't work
     
    <input type="submit" name="submit" value="Submit">&nbsp;&nbsp;
    <input type="button" value="Cancel" onclick="location.href='default.asp'">
    </form>
    Code:
    works but adds break after submit button
     
    <input type="submit" name="submit" value="Submit">&nbsp;&nbsp;
    </form>
    <input type="button" value="Cancel" onclick="location.href='default.asp'">

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sheesh, had a field named "location". Renamed it and it's ok now.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfectly OK to name that element what you like - so long as you explicitly scope the JS object reference:
    Code:
    <input type="submit" name="submit" value="Submit">&nbsp;&nbsp;
    <input type="button" value="Cancel" onclick="self.location.href='default.asp'">
    </form>
    Could be window, top, etc.
    Otherwise, it'll resolve to document.location, which usually works, but is nevertheless the wrong property (its been mapped, however).

    Edit:

    Sorry, should have made that clearer: without the window reference, it'll resolve to that element named 'location', as you observed. I meant that you should use the fully-qualified reference as a matter of course in these cases, to avoid any unintended resolution.
    Last edited by adios; May 5, 2004 at 15:23.
    ::: certified wild guess :::

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That makes sense, thanks for the help.


Bookmarks

Posting Permissions

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