SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onclick of radio button go to url

    hi,
    I want to connect the hyper of the new page to the onclick event of the radio button.
    The web page is developed in php and syntax is as follows

    echo """<input class="radio" type="radio" name="alg_Type" id="HP" value="HP" onclick="location.href='highP.php'"/><label class="choice" for="HP">High precision</label>""";

    and I get the following error
    Parse error: parse error, expecting `','' or `';''

    Any help would be appreciated.

    Thanks,

  2. #2
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    39,868
    Mentioned
    159 Post(s)
    Tagged
    4 Thread(s)
    Hi,

    I don't know anything about php (so I've no idea why I posted here) but shouldn't you be escaping the quotes inside the html or at least using double quotes on the outside and single quotes inside.
    e.g.
    Code:
    echo "<input class='radio' type='radio' name='alg_Type' id='HP' value='HP' onclick=\"location.href='highP.php'\"/><label class='choice' for='HP'>High precision</label>";
    Of course there's bound to be a much better way to do this.

    Why not just use a link to go to another page and not rely on javascript?

  3. #3
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    I agree with the above. Navigation using a radio button like that is a bad design decision. For one thing, they aren't meant for navigation, and another thing, it offers no more advantage than writing out a list of links. Use elements for their intended purposes. Radio buttons are form elements, designed to capture a decision, and then submitting it. Anchors are for navigation. Can it be done? Of course, but then again, you can use a crowbar to open your front door instead of your key, but why would you?

  4. #4
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies!
    I am sorry for not framing my question correctly. I am using two radio buttons. So when the radio button is selected, the page refreshes and uploads the different set of data. I was looking through the web and found that this is one of the ways to do it. Please let me know if there is a better to way to do it. I would appreciate any ideas or suggestions.
    Code:
     echo '<TR ><TD><input class="radio" type="radio" name="alg_Type" id="HP" value="HP" onclick="location.href=\'highHp.php\'"/>
    		<label class="choice" for="HP">High precision</label></TD></TR>';
    		echo '<TR ><TD><input class="radio" type="radio" name="alg_Type" id="HR" value="HR" onclick="location.href=\'highHR.php\'" />
    				<label class="choice" for="HR">High recall</label></TD></TR>';
    Many Thanks,

  5. #5
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Is the content of highHP and highHR being displayed under the radio buttons or just being uploaded to the server itself? Either way it's still a bad idea. I'd use a <select> dropdown to let the user choose (saves space on screen) with a small "GO" input button beside it to submit the form.

  6. #6
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply. Yes, there are two sets of data, so with the change of selection the displayed data set changes. I will try implementing the way you have suggested.
    Thanks again!


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
  •