Hi all,
I am having this problem, which I cant seem to find out why is happening.
I have an onchange function on one select list, which returns another select list just under, with values to choose from. But when the form is submitted, PHP gives me an error: Undefined index: placering ( I get the data as always: $pos = $_POST['placering']; )
echo '<select name="side_type" class="tab_form_select_wide" style="display:inline;"
onChange="hent_position_til_pdf(\'hoved\',this.selectedIndex);">';
echo '<option value="nej"> - Vælg en hovedside - </option>';
while (mysqli_stmt_fetch($STMT)) {
echo '<option value="'.$id.'">'.$hoved_link.'</option>';
}
echo '</select>';
The onchange function which handles the ajax call, and sends back a select list with relevant information:
function hent_position_til_pdf(side_type,id) {
var qstring = "side_type="+side_type+"&id="+id;
//alert(qstring);
// OPRET HTTP REQUEST:
if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); }
else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
setTimeout(function(){ document.getElementById("placeringer").innerHTML =
"<img src=\"styles/loader.gif\" width=\"26\" height=\"26\" style=\"display:inline;\" />" +
"<p style=\"display:inline; margin-left:15px; font-size:17px;\">" +
"<b>Henter placeringer...</b></p>"; },100);
setTimeout(function(){ document.getElementById("placeringer").innerHTML = xmlhttp.responseText },800 );
}
}
xmlhttp.open("GET", "ajaxPHP/moduler/pdf_position.php?"+qstring, true)
xmlhttp.send()
return false;
}
The file: pdf_position.php, where the new select list is being built and returned:
if (isset($_GET['side_type']) && isset($_GET['id'])) {
// print_r($_GET); exit(); // GIVES ME: Array ( [side_type] => hoved [id] => 3 )
// DATA:
$side_type = $_GET['side_type'];
$id = $_GET['id'];
$sql = "SELECT id, pos FROM modul_pdf WHERE side_id = ? AND side_type = ?";
$prep = mysqli_prepare($connection, $sql);
mysqli_stmt_bind_param($prep, "is", $id, $side_type);
mysqli_stmt_execute($prep);
mysqli_stmt_store_result($prep);
mysqli_stmt_bind_result($prep, $id, $pos);
$rows = mysqli_stmt_num_rows($prep);
if (is_numeric($id)) // Then return a list to the page
{
echo '<select name="placering" id="placering" class="tab_form_select_wide">';
for ( $i = 1; $i <= $rows + 1; $i++ )
{
echo '<option value="'.$i.'">'.$i.'</option>';
}
echo '</select>';
}
else // Return an empty list, stating to make a choise above..
{
echo '
<select name="placering" id="placering" class="tab_form_select_wide">
<option value="nej"> - Vælg først en side - </option>
</select>';
}
}
After these scripts has run, and I hit submit, I get an error from PHP, saying that there is an undefined index in the $_POST result. Which is the result I am trying to retrieve from the select list returned above..
Any ideas?
If I try to alert the xmlHTTP.responsetext, I can see the code to create the returned select list inside the alert box looks all fine.
So how come I get this error when I hit submit, and cant get acces to the options which the user has chosen??
/ Klemme