javascript - 2nd Submit Button Not Working on jQuery Click Event -
i creating quiz , can't figure out why 1 of submit buttons won't work.
here how quiz works:
on page load, questions appear, possible answers. when user selects reply , clicks "submit", or gets feedback on if reply correct. new button, named "next" presented @ bottom of page. when clicked, next question in array should display.
here problem:
the "next" button isn't doing when clicked. set alert test "next" button, it's not showing.
the on click function set previous one, working. i'm stumped.
here jsfiddle: http://jsfiddle.net/amykirst/3eubj/2/.
$(document).ready(function() { showquestion(); // when user clicks submit, grade question $("input[name='submit']").click(function() { //alert("line 118: clicked on submit"); gradequestion(); }); // when user clicks "next question", show next question $("input[name='next']").click(function() { alert("line 124: clicked on next"); // update currentquestion next question currentquestion++; //show question showquestion(); }); // prevent form refreshing page $("form").submit(function(e) { e.preventdefault(); }); }); // end document ready
depending on wether or not next button part of dom @ moment append event handler may want delegate click event parent button. way event handled on new elements added after handler has been registered.
$( '.container' ).on( 'click', 'input[name="next"]', function ( e ) { alert( 'load next question now!' ); } );
also see documentation deprecated .delegate() functionality originates.
javascript jquery forms
No comments:
Post a Comment