I have a form that I want to use to pass 2 values to a JS function using $_POST. I've tried doing just one at at time and it kind of worked, sometimes it would pass the value and sometimes it would be empty. I have two select in the form and I want to pass what is selected to the function. Here's what I've got:
<p>Add table to the Headings table</p>
<form action='Admin.php' enctype='multipart/form-data' method='POST' onsubmit="return AddTableName('<?php $_POST['TableName']; ?>','<?php $_POST['YesNo']; ?>')">
<input type='hidden' name='action' value='AddTable'>
<p>
<label><strong>Table Name:</strong>
<select name='TableName'><?php
foreach($TableNames as $Table)
{
//var_dump($Table);?>
<option value='<?php echo $Table; ?>'><?php echo $Table; ?></option><?php
}?>
</select>
</label>
</p><p></p>
<p>
<label><strong>Editable:</strong>
<select name='YesNo'>
<option value='No' selected='selected'>No</option>
<option value='Yes'>Yes</option>
</select>
</label>
</p><p></p>
<p><input type='submit' name='submit' value='Add Table'></p>
</form>
and here's the function:
function AddTableName(Name, Edit)
{
var y = confirm("Do you want to add this table: " + Name + "\nWith table Editable set to: " + Edit);
return y;
}
I know that the values get passed to $_POST when I click yes in the confirm pop-up, but I don't know that it always gets passed to $_POST before being sent to the function
EDIT
I've tried removing the onsubmit from the form and instead using
$Name = $_POST['TableName'];
$Edit = $_POST['YesNo'];
$Results = AddTableName('$Name','$Edit');
This results in my page going blank. So I don't know what if anything is being returned. What am I doing wrong?
POSTmethod? Why not pass the values and call function with buttononclick()?onClickit would mean that if I click anywhere in the form, not just on the button and that is not good for what I'm doing.onClickonly for the button, add this line of code:onclick="submitForm();"as an attribute to your button and define the function in<script>tag. You can also achieve this using jQuery with:$('#submit').click(function(){ ... }). (I assume your button's ID is submit).