SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    2 different behaviors on clicking

    Hello,

    I'm using some javascript to show a part of the page if a user answers a question correctly:
    Code JavaScript:
    <script type="text/javascript">
    $(document).ready(function(){
    	$('#solution').hide();
    	$('.magic_solution').click(function() {
    	$('#solution').slideToggle("slow");
    	return false;
    });
    });</script>
    Code HTML4Strict:
     <label>
      <input type="radio" name="subtracting_radio" value="yes" id="subtracting_radio_0" />
          yes</label>
     
        <label>
          <span class="magic_solution"><input type="radio" name="subtracting_radio" value="no" id="subtracting_radio_0" /></span>
          no</label></p>
     
    <div id="solution"><p><img src="../../images/user_reaction/correct_check.png" width="48" height="39" />  If you subtract 3 from 3 you get don't get a counting number.  Further, if you subtract 5 from 3 you don't get a counting number.</p>

    The code works in terms of the div solution is hidden until the user clicks "no". However, if the user clicks yes first and then no, the hidden solution shows, but the "no" button itself doesn't become selected. Is there anyway that I can add this in to my jquery code so that the button is highlighted as well? Or am I stuck with one behavior or the other?

    Thank you,

    Eric

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    The return false part is preventing the web browser from being able to perform its default behaviour.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks Paul! I had originally had it in there because I was using it to hide/unhide something when a user clicked on a link. However, it makes sense to me now that I'd want a "return false" for the link (or they'd go to another page) but not for the clicking on a bubble.

    Cheers!

    -Eric


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
  •