Jump to content

Ajax function only works once


trums

Recommended Posts

In this function I am attempting to grab the value of one of three radio buttons onclick. Then a lightbox is opened, inviting the user to add more information with a submit button. This works great until after you have gone through the process once. If you try to go through the process and 2nd time and click one of the radio buttons again, the submit button doesn't work! What can I do to make it work every time? The complete function is below:

 

#rvspNoteSave is the submit button and I used the Boxy lightbox: http://onehackoranother.com/projects/jquery/boxy/

 

$("#rvspForm input:radio").click(function(){
	var the_value = $(this).val();
			new Boxy('<div style="margin:5px;">Leave an rsvp note<br/><textarea id="rvspNote"></textarea><br/><div class="span-4"></div><div class="span-4 last"><a href="#" id="noteClose">No, Thanks</a> <input type="button" id="rvspNoteSave" value="Save"/></div><hr class="space"/></div>', {title: "Add A Note", closeable: true, afterShow: function() {
				$("#rvspNoteSave").click(function(){
					Boxy.get(this).hide();
				});
			}, afterHide: function() {
				$.ajax({  
					type: "POST",
					url: "http://localhost/events/ajax_savervsp/",
					data: "eventId="+eventId+"&note="+$("#rvspNote").val()+"&rvsp="+the_value,
					beforeSend:function() {
						$("#yourrvsp").html("<center><img src='http://p3.localhost:81/static/images/loader.gif'></center>");
					},
					success: function(data) { 
						$("#yourrvsp").html("<center><br/><b>Your RVSP:</b> "+data+"</center>").show();
					},
					error: function() {
						alert("Connection to server interrupted. Please try again.");
						$("#yourrvsp").html("");
					}
				}); 

			}});
});

 

Your help is greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/208299-ajax-function-only-works-once/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.