Welcome to The Scripts!
Since you have not posted all the code, it is a bit difficult to see what drop down values you want to mark. So let's take the code at line 20, select name ='vendor' and the option value from the db to be displayed is '$name'. Assuming you have POSTed the drop-downs using a submit of the form, then the code in that part would be something like:[php]echo "<option value='$name'";
if ($_POST['vendor'] == $name)
echo " selected='selected' ";
echo ">$name</option>";[/php]If that is not what you are looking for, then show all code involved (and within the appropriate code tags this time) and we can see what is going on.
Ronald
Thanks Ronald. Yes, what I am trying to do is this in more detail:
I am using PHP/MYSQL/AJAX for inserting to database using the form which has dependent drop down list. The problem here is I am not able to see the values of variables that I need for inserting to the DB in the MainPage.php I have used the POST part of the code also that you had suggested. I think I am making a mistake in the form but not sure how... Please let me know if this is clear?
The main Page has
MainPage.php: This is the form in the Main Page where I am trying to get the values to be assigned to two variables $vendor and $vendorrecruiter. As long as i am able to echo/print this values in this mainpage.php the code wil work.[php]
[php]?include 'inc/ajax.js'?>
<FORM action="job_orders_test.php" method=post>
<TR>
<td width="4%" ><b><font face="Arial Narrow" size="2"> ID</font></b></td>
<td width="13%" > <INPUT name=jobid value="<?= $jobid ?>" size=9></td>
<td width="6%" ><b><font face="Arial Narrow" size="2">Title</font></b></td>
<td align="justify" width="38%" ><input name=jobtitle value="<?= $jobtitle ?>" size="32" ></td>
<td width="6%" ><b><font face="Arial Narrow" size="2">Rate</font></b></td>
<td width="12%" ><input size=9 name=rate value="<?= $rate ?>"></td>
<td width="12%" ><b><font face="Arial Narrow" size="2">Vendor Rate</font></b></td>
<td width="10%" ><input size=9 name=vendorrate value="<?= $vendorrate ?>"></td>
</TR>
<TR>
<td align="center" width="50%" colSpan="8" height="24"><b>
<font face="Arial Narrow" size="2">
<?
echo "<form name=sel>\n";
echo "VENDOR : <font id=vendor face=\'Arial Narrow'\ size=2><select>\n";
echo "<option value='0'>============</option> \n" ;
echo "</select></font>\n";
echo "RECRUITER : <font id=vendorrecruiter face=\'Arial Narrow'\ size=2><select>\n";
echo "<option value='0'>=== none ===</option> \n" ;
echo "</select></font>\n";
$vendor=$_GET['vendor'];
echo " We have - $vendor & - $vendorrecruiter ";
?>
</font>
</td>
</TR>
<TR>
<td align="middle" width="100%" colSpan="8" height="24"><b>
<font face="Arial Narrow" size="2"> POC </font></b>
<SELECT style="WIDTH: 238px" size="1" name=poc >
<OPTION value="RECRUITER" selected>RECRUITER</OPTION>
</SELECT>
<font face="Arial" size="2">   ; </font>
</td>
</TR>
</TBODY></TABLE></DIV>
<TR>
<TD width="100%" height=12 bgColor="#ff9966"> <b><font face="Arial Narrow" size="2">
<P align="center">
<INPUT TYPE="hidden" name=tried value="yes">
<INPUT name=B1 type=submit value=Submit> <INPUT name=B2 type=reset value=Clear> </P>
</FORM>
_______________________________
ajax.js
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(src, val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.respons eText; //retuen value
}
}
};
req.open("GET", "vendor.php?data="+src+"&val="+val); //make connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
req.send(null); //send value
}
window.onLoad=dochange('vendor', -1); // value in first dropdown
</script>
__________________________________________________ _
vendor.php
<?
//set IE read from page only not read from cache
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
include 'inc/dbcon.php';
//set database
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
if ($data=='vendor') { // first dropdown
echo "<select name='vendor' onChange=\"dochange('vendorrecruiter', this.value)\">\n";
echo "<option value='0'>==== Choose vendor ====</option>\n";
$result=mysql_db_query($dbname,"select `clientid`, `companyname` from rtracker_vendor group by `companyname`");
while(list($id, $name)=mysql_fetch_array($result)){
echo "<option value='$name'";
if ($_POST['vendor'] ==$name) echo " selected ='selected'";
echo" >$name</option> \n" ;
}
} else if ($data=='vendorrecruiter') { // second dropdown
echo "<select name='vendorrecruiter' >\n";
echo "<option value='0'>====Choose recruiter ====</option>\n";
$result=mysql_db_query($dbname,"SELECT `clientid`, `name` FROM rtracker_vendor where `companyname` like '%$val%' ORDER BY `name` ");
while(list($id, $name)=mysql_fetch_array($result)){
echo "<option value='$name'";
if ($_POST['vendor'] ==$name) echo " selected ='selected'";
echo" >$name</option> \n" ;
}
}
echo "</select>\n";
?>[/php]