Lia Nungaray
asked on
Populating textboxes upon drop down selection
I finally thought that I had found the answer to my dilema, but not quite yet. I have the following code which populates ONE textbox when the user makes a selection. I actually need TWO textboxes to be populated, but unfortunately, the code that I have doesn't seem do be built to just add a little more code to satisfy this need. Here's the code:
<?php
//Connect to the db.
$dbc = mysql_connect('localhost', 'root','') ;
mysql_select_db('productio n',$dbc);
echo "
<html>
<head>
<script language=\"javascript\">
function getCustName()
{
document.myform.ldgact.val ue=documen t.myform.a ppnbr.valu e;
}
</script>
</head
<body>
<form method=\"POST\" name=\"myform\" action=\"add_scan.php\">
<p>Account Number:<input type=\"text\" name=\"ldgact\" size=\"50\"></p>
<p>Production Date:<input type=\"text\" name=\"datprd\" size=\"10\"></p>>";
$query="SELECT APPNBR, CUSTNAME, DATPRD FROM tblappearance, tblcustomers WHERE tblappearance.ldgact=tblcu stomers.mc ustnbr";
if ($hResult=mysql_query($que ry))
{
while ($hFetch=mysql_fetch_array ($hResult) )
{
$appnbr=$hFetch["APPNBR"];
$custname=$hFetch["CUSTNAM E"];
echo "<option value='$custname'\">".$app nbr."</opt ion>";
}
}
echo "
</select>
</form>
</body>
</html>";
Any suggestions will be welcome. Thanks!
<?php
//Connect to the db.
$dbc = mysql_connect('localhost',
mysql_select_db('productio
echo "
<html>
<head>
<script language=\"javascript\">
function getCustName()
{
document.myform.ldgact.val
}
</script>
</head
<body>
<form method=\"POST\" name=\"myform\" action=\"add_scan.php\">
<p>Account Number:<input type=\"text\" name=\"ldgact\" size=\"50\"></p>
<p>Production Date:<input type=\"text\" name=\"datprd\" size=\"10\"></p>>";
$query="SELECT APPNBR, CUSTNAME, DATPRD FROM tblappearance, tblcustomers WHERE tblappearance.ldgact=tblcu
if ($hResult=mysql_query($que
{
while ($hFetch=mysql_fetch_array
{
$appnbr=$hFetch["APPNBR"];
$custname=$hFetch["CUSTNAM
echo "<option value='$custname'\">".$app
}
}
echo "
</select>
</form>
</body>
</html>";
Any suggestions will be welcome. Thanks!
Hi horalia,
1. I hope that is not your real user/pass and if so you should never run as root.
2. Where do you open your <select>
3. In the javascript part just fill in the other textboxs with the value you want. (I can't tell what it is you want, I only see 2 textfields)
Joe P
1. I hope that is not your real user/pass and if so you should never run as root.
2. Where do you open your <select>
3. In the javascript part just fill in the other textboxs with the value you want. (I can't tell what it is you want, I only see 2 textfields)
Joe P
ASKER
No, it's not. It's password protected, I just erase it whenever I copy some code on the web. I erased the fields just to show what I currently have that works. Here's my complete working code:
<?php
//Connect to the db.
$dbc = mysql_connect('localhost', 'root','') ;
mysql_select_db('productio n',$dbc);
echo "
<html>
<head>
<script language=\"javascript\">
function getCustName()
{
document.myform.custname.v alue=docum ent.myform .appnbr.va lue;
}
</script>
</head>
<body>
<form method=\"POST\" name=\"myform\" action=\"add_scan.php\">
<p>
Customer Name:
<input type=\"text\" name=\"custname\" size=\"50\">
</p>
<p>
Production Date:
<input type=\"text\" name=\"datprd\" size=\"10\">
</p>
<p>
Insertion Order Number:
<select size=\"1\" name=\"appnbr\" onChange=\"getCustName()\" >";
$query="SELECT APPNBR, CUSTNAME, DATPRD FROM tblappearance, tblcustomers WHERE tblappearance.ldgact=tblcu stomers.mc ustnbr";
if ($hResult=mysql_query($que ry))
{
while ($hFetch=mysql_fetch_array ($hResult) )
{
$appnbr=$hFetch["APPNBR"];
$custname=$hFetch["CUSTNAM E"];
$datprd=$hFetch["DATPRD"];
echo "<option value='$custname'\">".$app nbr."</opt ion>";
}
}
echo "
</select>
</form>
</body>
</html>";
My final purpose is to add some extra fields for the user to fill in and post all this information to the database. I already have the posting part working, this is just a separate file where I'm trying to make the drop-down boxes work, then I will use this file to post the values. Just wanted to let you know if there are some precautions I should take when doing this. Thanks!
<?php
//Connect to the db.
$dbc = mysql_connect('localhost',
mysql_select_db('productio
echo "
<html>
<head>
<script language=\"javascript\">
function getCustName()
{
document.myform.custname.v
}
</script>
</head>
<body>
<form method=\"POST\" name=\"myform\" action=\"add_scan.php\">
<p>
Customer Name:
<input type=\"text\" name=\"custname\" size=\"50\">
</p>
<p>
Production Date:
<input type=\"text\" name=\"datprd\" size=\"10\">
</p>
<p>
Insertion Order Number:
<select size=\"1\" name=\"appnbr\" onChange=\"getCustName()\"
$query="SELECT APPNBR, CUSTNAME, DATPRD FROM tblappearance, tblcustomers WHERE tblappearance.ldgact=tblcu
if ($hResult=mysql_query($que
{
while ($hFetch=mysql_fetch_array
{
$appnbr=$hFetch["APPNBR"];
$custname=$hFetch["CUSTNAM
$datprd=$hFetch["DATPRD"];
echo "<option value='$custname'\">".$app
}
}
echo "
</select>
</form>
</body>
</html>";
My final purpose is to add some extra fields for the user to fill in and post all this information to the database. I already have the posting part working, this is just a separate file where I'm trying to make the drop-down boxes work, then I will use this file to post the values. Just wanted to let you know if there are some precautions I should take when doing this. Thanks!
All you need to do is pretty much copy this line in your javascript function:
document.myform.ldgact.val ue = document.myform.appnbr.val ue;
Change the "ldgact" of the first part to the name of the textfield you want.
If I understand correctly you want two textboxes to have the value of the drop down box.
Joe P
document.myform.ldgact.val
Change the "ldgact" of the first part to the name of the textfield you want.
If I understand correctly you want two textboxes to have the value of the drop down box.
Joe P
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'll try your suggestions. Thanks!
ASKER
Thanks Roonan! Worked great!
ASKER