SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict Volitics's Avatar
    Join Date
    Aug 2003
    Location
    US
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to make onClick radio button redirect.

    Can anybody explain to me how to rewrite the JavaScript below.

    What the script below does is when you click the radio button it redirects the user to another page.

    I used an old version of Dreamweaver to generate the code. It works ok the way it is but I need to make it simple enough so I can understand it a little better.

    Dreamweaver makes JavaScript seem more complicated that it actually is. Is there any kind of tutorial and someone can direct me to?
    PHP Code:
    <script language="JavaScript">
    <!--
    function 
    MM_goToURL() { //v3.0
      
    var iargs=MM_goToURL.argumentsdocument.MM_returnValue false;
      for (
    i=0i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
    }
    //-->
    </script>



    <input type="radio" name="radiobutton" value="first" onClick="MM_goToURL('parent','/register/TestJS.html');return document.MM_returnValue"> 
    Thanks.

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dreamweaver makes JavaScript seem more complicated that it actually is.
    Yes. A lot of people on javascript forums, including me, won't even look at Dreamweaver code.

    Is there any kind of tutorial and someone can direct me to?
    Javascript is widely documented on the net, and there are literally thousands of tutorials. You can search google.

    However, what you want to do is as simple as this:

    Code:
    onclick = "document.location.href='somepage.htm'"

  3. #3
    SitePoint Addict Volitics's Avatar
    Join Date
    Aug 2003
    Location
    US
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    7stud;

    It works great! Thanks for the help.

    I did a search on the SitePoint JS forum a little earlier and found similar code. I tried it but it didn't work. But what I earlier forgot to do - I didn't put the onclick code inside <form> tags. No wonder it wouldn't work.

    Thanks again for the help.

  4. #4
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44° 56.537' W 123° 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's also valid markup to put a radio button input inside an anchor tag sporting a href.

  5. #5
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to redirect a radio button without JavaScript.

    Hi, there. I'm trying to put a radio button input inside an anchor tag with its href, like you guys suggested, but even though the browser shows the url at the bottom when the mouse is on the radio button, it doesn't redirect when it's clicked.

    The onclick = "document.location.href='somepage.htm'" works fine, but...can it redirect while sending a jsp parameter to the destination document at the same time?

    Since I'm coding on xhtml and trying to send a parameter from the .jsp document where the clicked radio button is on to another .jsp document, I'm not sure if it's better not to use any JavaScript based code, like the "onclick", and do everything xhtml, html and jsp instead. That's why I'm interested in the "<a href..." option.

    Has anyone tryed successfully to redirect a radio button without any JavaScript? Is there any way of doing it in html, xhtml and jsp only?

    Thank you in advance for any hint or help.

    Héctor.

  6. #6
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    onclick="location.href='somepage.htm?myvar=myval&amp;myvar2=myval2'"
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


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
  •