Jump to content

Populate textboxes upon drop down onchange


horaliar

Recommended Posts

I have the following code which populates a drop down list from a MySQL database:

<html>
<head>
<title>Imaging Scanning Log</title>
</head>

<?php
//Connect to the db.
require_once('mysql_connect.php');
?>

Select Insertion Order Number:
<select name="APPNBR">
<?php
//Build query to retrieve data to populate drop-down list
$query = "SELECT APPNBR FROM tblAppearance";

//Execute query
$result = @mysql_query($query);

//Loop through the results
while($row = mysql_fetch_array($result))
{
//Assign returned values to the variables
$APPNBR1 = $row['APPNBR'];?>
<option value="<?php echo $APPNBR1;?>"><?php echo $APPNBR1;?></option>
<?php
}
?>
</select>

<p></p>
Customer Name:
<input type="text" name="custname">
<p></p>
Date Published:
<input type="text" name="pubdate">
</html>

I would like to run the following query to insert the results into "custname" and "pubdate".

"SELECT custname, datprd FROM tblappearance, tblcustomers
WHERE tblappearance.ldgact=tblcustomers.mcustnbr
AND tblappearance.appnbr=$APPNBR1"

How can I do this? The only programming experience I have is with Access, and this task is accomplished so easily using this database, that I'm getting a little overwhelmed. Thanks!
Link to comment
Share on other sites

You're not forming your question very well..

After reading it quite a bit I found out what you meant!

[code]<?php
$query = "SELECT custname, datprd FROM tblappearance, tblcustomers
WHERE tblappearance.ldgact=tblcustomers.mcustnbr
AND tblappearance.appnbr=$APPNBR1";

$result = mysql_query ( $query );
$data = mysql_fetch_array($result); // no need to loop since we are only concerned with row 1..
?>
Customer Name:
<input type="text" name="custname" value="<?=$data[custname];?>">
<p></p>
Date Published:
<input type="text" name="pubdate" value="<?=$data[datprd];?>">
</html>[/code]

Should get ya what you're thinking of [=



Link to comment
Share on other sites

Thanks! What I am really looking for is that the textboxes be updated every time a selection is made. I enclosed your code in a function:

<?php
function mine()
{
$query = "SELECT custname, datprd FROM tblappearance, tblcustomers
WHERE tblappearance.ldgact=tblcustomers.mcustnbr
AND tblappearance.appnbr=$APPNBR1";

$result = mysql_query ( $query );
$data = mysql_fetch_array($result); // no need to loop since we are only concerned with row 1..
}
?>

And I tried calling it using the onchange event, but I don't think I'm using the right syntax:

<select name="APPNBR" onchange="<?php "mine" ?>">"

Any ideas? Thanks!



Link to comment
Share on other sites

[!--quoteo(post=358068:date=Mar 24 2006, 09:39 PM:name=Horalia)--][div class=\'quotetop\']QUOTE(Horalia @ Mar 24 2006, 09:39 PM) [snapback]358068[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I did some reading and found out that I can't do it this way, that I have to reload the form and run the code from JavaScript?
[/quote]

Well.. JavaScript and PHP can function together using a method known as AJAX.. which seems to be what you want to do.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.