Hi all.

I have read very post concerning the "select OnChange event" but can not find an anwser to my issue.

I have a form with a list box which gets its data from a SQL table.

What I am trying to do is when an item is selected from the list, submit the form data to the same page, run a query and display the result on the same page.

This is what I have so far:

The form:

<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" >

select name="select" id="select" onChange="this.form.submit()">
<option value="">Please select </option><?php
do {  
?> <option value="<?php echo $row_embassies['RecordID']?>"><?php echo $row_embassies['Description']?></option><?php } while ($row_embassies = mysql_fetch_assoc($embassies)); $rows = mysql_num_rows($embassies); if($rows > 0) { mysql_data_seek($embassies, 0); $row_embassies = mysql_fetch_assoc($embassies); } if($_POST['formSubmit'] == "Submit") { ?> echo $row_EmbassyLookup['Description']; ?></td> echo $row_EmbassyLookup['Address']; ?></td> echo $row_EmbassyLookup['TeleNumber']; ? echo $row_EmbassyLookup['OfficeHours']; ?></td> <? } ?> </form>

The Query:


if($_POST['formSubmit'] == "Submit")  {  // This works only if I have a submit button

$colname_EmbassyLookup = "-1";
if (isset($_POST['select'])) {
  $colname_EmbassyLookup = $_POST['select'];
}
mysql_select_db($database_flightq, $flightq);
$query_EmbassyLookup = sprintf("SELECT * FROM UKEmbassies WHERE RecordID = %s", GetSQLValueString($colname_EmbassyLookup, "int"));
$EmbassyLookup = mysql_query($query_EmbassyLookup, $flightq) or die(mysql_error());
$row_EmbassyLookup = mysql_fetch_assoc($EmbassyLookup);
$totalRows_EmbassyLookup = mysql_num_rows($EmbassyLookup);
}


?>

Can anyone provide some help.

UPDATE: Found a solution and is working as expected.

    Write a Reply...