SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I'd like to do is have a check beside a link. If the box is checked, the user will be taken to page A. If unchecked (default) the user will be taken to page B.

    Can javascript be used to do this?

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    northern Maine
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <a href="javascript://" onclick="if(document.forms['form_name'].elements['checkbox_name'].checked)window.location.href='pageA.html';else window.location.href='pageB.html'">

    Use that as your link.
    Jason - Contact Me
    Supermoderator @ CodingForums

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Much cleaner than what I was working on just now...

    What is the '://' for in the href tag?
    - Mike
    http://www.georgiaoffroad.com

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    northern Maine
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    href="javascript://"

    Tells the browser to do nothing when the href is activated.

    Also familiar ways of doing that is:

    href="#"
    href="javascript:void(null)"
    href="javascript:void(0);"

    And so on.
    Jason - Contact Me
    Supermoderator @ CodingForums

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With your example the user is automatically taken to the next page when the checkbox is selected.

    What I'm going for is to have the user select the checkbox, but only when the corresponding link is clicked will the script run.

    That sounds awfully vague without seeing what I'm doing...

    O TEXTLINK

    When the TEXTLINK is clicked without a check in the O (checkbock), it fowards the user to ONE.HTM.

    Conversly, if the checkbox 'O' beside TEXTLINK is selected, when the user clicks TEXTLINK he is taken to TWO.HTM.

    No action should occur when the checkbox is selected in and of itself. The user must click the TEXTLINK for any action to take place.
    - Mike
    http://www.georgiaoffroad.com

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    northern Maine
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It will not go automatically, you must have used it wrong. Use this:

    <form name="red"><input type="checkbox" name="bla" /></form>&nbsp;<a href="javascript://" onclick="if(document.forms['red'].elements['bla'].checked)window.location.href='pageA.html';else window.location.href='pageB.html'">Something</a>
    Jason - Contact Me
    Supermoderator @ CodingForums


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
  •