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('production',$dbc);

echo "

<html>
<head>
<script language=\"javascript\">
function getCustName()
{
  document.myform.ldgact.value=document.myform.appnbr.value;
}

</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=tblcustomers.mcustnbr";

      if ($hResult=mysql_query($query))
      {
              while ($hFetch=mysql_fetch_array($hResult))
              {
                $appnbr=$hFetch["APPNBR"];
                $custname=$hFetch["CUSTNAME"];

                echo "<option value='$custname'\">".$appnbr."</option>";
              }
      }

echo "

</select>
</form>
</body>
</html>";

Any suggestions will be welcome. Thanks!
Horalia RodriguezIT DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Horalia RodriguezIT DeveloperAuthor Commented:
Just to clarify, I want DATPRD to be filled in a third text box.
0
BogoJokerCommented:
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
0
Horalia RodriguezIT DeveloperAuthor Commented:
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('production',$dbc);

echo "

<html>
<head>
<script language=\"javascript\">
function getCustName()
{
  document.myform.custname.value=document.myform.appnbr.value;
}
</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=tblcustomers.mcustnbr";

if ($hResult=mysql_query($query))
{
  while ($hFetch=mysql_fetch_array($hResult))
  {
    $appnbr=$hFetch["APPNBR"];
    $custname=$hFetch["CUSTNAME"];
    $datprd=$hFetch["DATPRD"];
    echo "<option value='$custname'\">".$appnbr."</option>";
  }
}

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!
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

BogoJokerCommented:
All you need to do is pretty much copy this line in your javascript function:
document.myform.ldgact.value = document.myform.appnbr.value;

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
0
RoonaanCommented:
Hi,

You could have:

echo "<option value='$custname||$datprd'\">".$appnbr."</option>";

Then change your function to:

<select size=\"1\" name=\"appnbr\" onChange=\"getCustName(this)\">";

function getCustName(selBox)
{
  var doubleValue = selBox.options[selBox.selectedIndex].value.split('||');
  selBox.form.custname.value=doubleValue[0];
  selBox.form.datprd.value=doubleValue[1];
}

You have to make sure that the two pipes are not in either custname or datprd, otherwise use another delimiter.

-r-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Horalia RodriguezIT DeveloperAuthor Commented:
I'll try your suggestions. Thanks!
0
Horalia RodriguezIT DeveloperAuthor Commented:
Thanks Roonan! Worked great!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.