Reputation: 141
I have a div element which will auto populate a list of checkboxes on changing a value from another drop down list. The checkboxes are populated fine, however the 'pl' parameter cannot be posted over to the other form, createreport.php on submitting the form.
Entry form:
$.ajax({
type: "POST",
url: "loadData.php",
data: dataString,
cache: false,
success: function(result){
$("#loader").fadeOut(600);
$("#inputpl").empty().append(result);
}
});
<form action="createreport.php" method="post">
<div class="form-dropdown" style="width:300px" id="inputpl" name="pl">
//////////checkboxes populated here. If I hard code the checkboxes here, it can be passed over successfully
</div>
<input type="submit" />
</form>
loadData.php:
for($i=0; $i<=odbc_fetch_row($result); $i++){
$name = odbc_result($result, 1);
echo '<input type="checkbox" name="pl[]" value="'.$name.'" />'.$name.'<br/>';
}
createreport.php:
echo '<pre>';
print_r($_POST['pl']);
echo '</pre>';
Output:
Notice: Undefined index: pl in C:\inetpub\wwwroot\test\createreport.php on line 21
EDIT: I am able to alert the value of the checkboxes by adding this to the submit button:
$('input[type="checkbox"]:checked').each(function(){
alert(this.value);
})
Upvotes: 0
Views: 71
Reputation: 608
I think you have submit the form without checking any checkboxes thats why the error is reported
please try following code
if(isset($_POST['pl'])){
echo '<pre>';
print_r($_POST['pl']);
echo '</pre>';
}
Upvotes: 0
Reputation: 27247
for($i=0; $i<=odbc_fetch_row($result); $i++){
$name = odbc_result($result, 1);
echo '<input type="checkbox" name="pl[]" value="'.$name.'" />'.$name.'<br/>';
}
odbc_fetch_row
returns a boolean for a successful fetch. You want this:
<?php
while (odbc_fetch_row($result)) {
$name = odbc_result($result, 1);
echo '<input type="checkbox" name="pl[]" value="'.$name.'" />'.$name.'<br/>';
}
It doesn't look like anything would have been returned from loadData.php anyway.
Upvotes: 1