Jump to content

Jquery form in while loop


Recommended Posts

Hello I have example database where is (Few values added)

ID, SUBJECT, NAME1, Hello world, Mudsaf2, Hello world2, Mudsaf

Then i get the data from sql with query (querys and row works perfectly

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script><script src="http://malsup.github.com/jquery.form.js"></script>  <script>		// wait for the DOM to be loaded		$(document).ready(function() {			// bind 'myForm' and provide a simple callback function			$('#removepost').ajaxForm(function() {				alert("Something happened");			});		});	</script> <?php$query  = "blablaablla"... untill while  ($row = mysql_fetch_array($result)) {  echo "<form id='removepost' method='post' action='script/removepost.php'>  <input type='hidden' readonly='readonly' name='id' id='id' value='1' />  <input type='submit' name='submit' id='submit' value='Remove'></form>" . $row['SUBJECT']; } ?>

The form works perfectly, but doesn't work with jQuery.

http://malsup.com/jquery/form/  <--- This method doesn't work 

So im wondering is it possible to get that script work OR where do i link the jQuery files. So currenctly it goes to script/removepost.php, but it should stay at same page and let jQuery run the script whitout page refreshing/moving to action file. Should the form be changed from id to class and in jquery the #removepost to .removepost?

Edited by Mudsaf
Link to post
Share on other sites

Remove any of the form elements you don't want to repeated from the while loop, ie form element opening and closing tags, and submit button, i would also change id and name value of 'id' as i think you will find it will cause confusion in javascript.

  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...