how to seperate php generated buttons
I'm generating tables of buttons with php
- echo ' <td">
- <form action="test.php" method="POST">
- <input type="hidden" id="node" name="node" value="'.$fnode->{'name'}.'">
- <input type="hidden" id="service" name="service" value="'.$flavor.'">
- <input type="hidden" id="running" name="running" value="false">
- <input type="submit" value="OFF" class="button">
- </form>
- </td>';
I want to send the values without reloading via jquery ajax and I'm using this code for it:
- $(".button").click(function() {
- $('.error').hide();
-
- var dataString = 'node='+ document.getElementById('node').value + '&service=' + document.getElementById('service').value + '&running=' + document.getElementById('running').value;
-
- $.ajax({
- type: "POST",
- url: "test.php",
- data: dataString,
- success: function() {
- alert ("Success");
- }
- });
- return false;
- });
Code works so far - it just always sends the data from the first form. What is the best way to distinguish between all the buttons. I could use a counter in the form, but how would I exactly write the js "ifs".
Is there a more elegant way to do this. Number of forms is dynamic.
Thank you for your time