I have divs generating for each called result from a database. within that div I am able to display the specific dataset from the db to populate it. Now I have a form that I am trying submit with js that is specific to each called div and opens the file for processing the form in another div(this works as a standalone but the js is not encased within a php echo). I originally assumed the best process was to simply include the js within the echo result(the js also works as a standalone). Instead of submitting the form and loading the page in the appropriate div(static div name), it will load the main page with the date submitted as a string within the url.
http://localhost/3/?item-id=6&onhand=4#
This is the js within the echo statement(at the beginning of the echo)
<script>
$(document).ready(function() {//start document ready
$('#b_" . $row['id'] . "').click(function (e){
e.preventDefault();
$.ajax({
type: 'POST',
url: 'pages/work.php',
data: $('#f_" . $row['id'] . "').serialize(),
success: function(d){
$('#notice').html(d);
}
});
});
});//end document ready
</script>
Here is the form portion of the echo
<form id=\"f_" . $row['id'] . "\">
<input type=\"hidden\" name=\"item-id\" id=\"item-id\" value=\"" . $row['id'] . "\">
<select name=\"onhand\" class=\"onhand\" id=\"onhand\ >
<option value=\"0\">0</option>
<option value=\"1\">1</option>
<option value=\"2\">2</option>
<option value=\"3\">3</option>
<option value=\"4\">4</option>
<option value=\"5\">5</option>
<option value=\"6\">6</option>
<option value=\"7\">7</option>
<option value=\"8\">8</option>
<option value=\"9\">9</option>
<option value=\"10\">10</option>
</select>
<button id=\"b_" . $row['id'] . "n\">Order " . $row['item'] . "</button>
</form>
I believe there is a most likely a way to use the js outside of the php and having the submit button activate the js using the appropriate php/form variables.
Any help would be much appreciated!
~ Leo