Jump to content

If Statement within JQuery Function


kingnutter

Recommended Posts

I have a form which can be submitted with two button options:

 

<input type="button" name="submit1" id="submit1" value="Add and Close" />
<input type="button" name="submit2" id="submit2" value="Add and Add More" />

 

I then want a JQuery function to behave slightly differenly depending on which button has been pressed. Something along these lines:

<script type="text/javascript" charset="utf-8">

	$(':button').click(function() {

		var moj_id = $('#moj_id').val();
		var track_no = $('#track_no').val();
		var track_title = $('#track_title').val();
		var track_artist = $('#track_artist').val();
		var track_asinuk = $('#track_asinuk').val();
		var track_asinus = $('#track_asinus').val();

		$.post('../includes/add_track_to_db.php', {
		    'moj_id' : moj_id,
		    'track_no' : track_no,
		    'track_title' : track_title,
			'track_artist' : track_artist,
			'track_asinuk' : track_asinuk,
			'track_asinus' : track_asinus
			},

			function(r) {

				$('<div class="overlay"></div>')
				    .appendTo('#form_block')
					.fadeIn(1000, function() { 

						$('<tr><td>' + r + '</td></tr>')
							//.hide()
							.appendTo('table#tracks') 
							.fadeIn(1000, function() { 

if('#submit1'){ // should this be an if == true?

							    $('#form_block').slideUp(1000, function() {

									$('.overlay').hide()

								});

} // end submit1 if



if('#submit2'){   // should this also be an if == true? Or an else?

									$('.overlay').hide();

} // end submit2 if


							}); 

				// clears form
				document.getElementById('form').reset(); 

				//

				});

			}

		);

		return false; // disable submit click

	});

</script>

But it's not working.

 

Can anybody point out the errors in my syntax or am I going about this the wrong way completely?

 

Thanks,

KN

Link to comment
https://forums.phpfreaks.com/topic/202247-if-statement-within-jquery-function/
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.