Re: How do I display the selected values in page?
|
Poutt Keitis |
|
3/27/2008 12:46:08 AM |
Code: ( php ) - echo "<option value=\"$name\">$name</option>
\n" ;
- page1.php
-
<?
-
echo "<form name=sel>\n";
-
echo "VENDOR : <font id=vendor><select>\n";
-
echo "<option value='0'>============</option> \n" ;
-
echo "</select></font>\n";
-
echo "RECRUITER : <font id=vendorrecruiter ><select>\n";
-
echo "<option value='0'>=== none ===</option> \n" ;
-
echo "</select></font>\n";
-
?> - page2.php
- 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\">$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=\"$id\" >$name</option> \n" ;
-
} - }
- echo "</select>\n";
Post Comments |
|
Re: How do I display the selected values in page?
|
Potthaccio Vaavaacione |
|
3/27/2008 12:49:35 AM |
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: Code: ( php ) echo "<option value='$name'"; if ($_POST['vendor'] == $name)
echo " selected='selected' ";
echo ">$name</option>"; 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.
Post Comments |
|
Ahh,, It was selected='selected' and not checked='checked'. :p
Thanks for that. ;)
I can use that in my script. :)
Greetings, Post Comments |
|
Re: Hope you can continue now without problems
|
Potthaccio Vaavaacione |
|
3/27/2008 12:54:11 AM |
Hope you can continue now without problems. See you next time.
Post Comments |
|
Re: You can also use only selected
|
Raphaelin Mantein |
|
3/27/2008 12:56:28 AM |
You can also use only selected instead of selected='selected', and similarly in case of checked='checked' Post Comments |
|
Re: Yes, what I am trying to do is in more detail
|
Poutt Keitis |
|
3/27/2008 12:59:45 AM |
Thanks Poththacci. 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. Code: ( 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">
- [B] <?
-
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 ";
-
?>[/B] -
</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>
- _______________________________
- [U][B]ajax.js[/B][/U]
- <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>
- __________________________________________________
_ - [B]vendor.php[/B]
- <?
- //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";
- ?>
Post Comments |
|
Re: No referring of your code
|
Potthaccio Vaavaacione |
|
3/27/2008 1:01:55 AM |
Since you chose to ignore the request to follow the Posting Guidelines and show your code witin the appropriate code tags, which has been asked before, I will not look any further at your code.
Post Comments |
|
Re: Sorry I did not see the code tags message
|
Poutt Keitis |
|
3/27/2008 1:03:28 AM |
Sorry I did not see the code tags message while I was posting. Can I repost it? Or how do I edi t my post? Post Comments |
|
Re: Please enclose any code within the proper code tags
|
Potthaccio Vaavaacione |
|
3/27/2008 1:04:58 AM |
Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that.
Post Comments |
|