Jump to content


Photo

Populate textboxes upon drop down onchange


  • Please log in to reply
4 replies to this topic

#1 horaliar

horaliar
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 24 March 2006 - 08:21 PM

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!


#2 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 24 March 2006 - 08:51 PM

You're not forming your question very well..

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

<?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>

Should get ya what you're thinking of [=




Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#3 horaliar

horaliar
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 24 March 2006 - 09:08 PM

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!





#4 horaliar

horaliar
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 24 March 2006 - 09:39 PM

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?

#5 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 24 March 2006 - 11:31 PM

[!--quoteo(post=358068:date=Mar 24 2006, 09:39 PM:name=Horalia)--][div class=\'quotetop\']QUOTE(Horalia @ Mar 24 2006, 09:39 PM) View Post[/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.

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users