?
Solved

Populating textboxes upon drop down selection

Posted on 2006-03-27
7
Medium Priority
?
367 Views
Last Modified: 2011-09-20
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!
0
Comment
Question by:horalia
  • 4
  • 2
7 Comments
 

Author Comment

by:horalia
ID: 16306269
Just to clarify, I want DATPRD to be filled in a third text box.
0
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16306296
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
 

Author Comment

by:horalia
ID: 16306379
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 17

Expert Comment

by:BogoJoker
ID: 16306417
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
 
LVL 49

Accepted Solution

by:
Roonaan earned 1200 total points
ID: 16307581
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
 

Author Comment

by:horalia
ID: 16312279
I'll try your suggestions. Thanks!
0
 

Author Comment

by:horalia
ID: 16312345
Thanks Roonan! Worked great!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question