forms: PHP/JavaScript/MySQL automatic field filling

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PinkFloyd
Forum Newbie
Posts: 3
Joined: Tue Dec 19, 2006 7:45 am

forms: PHP/JavaScript/MySQL automatic field filling

Post by PinkFloyd »

Hello,

Question:

I'm trying to make a form to add error log entries into a database.
Some error codes are already known in the DB, others are not.

What I want to do, is the following: when people fill in an existing error code in the designated field, I want to display the description of that error code in another field from the moment they leave the error code field (onChange).

I think this should involve both PHP and JS, but I can't figure out how...

Also, to make things easy, I want users to be able to enter 10 new records at a time, so I need to work with an array indicator, or something.

Here's parts of the page as it is now:

Code: Select all

<form action="cl-el-de-post.php" method="post" name="cl-el-de">
<table class="ContentTable" cellspacing="0">
  <tr>
    <td class="ContentText">Date<br />Collected</td>
    <td class="ContentText">Technician</td>
    <td class="ContentText">Error Code</td>
    <td class="ContentText">Date</td>
    <td class="ContentText">Time</td>
    <td class="ContentText"># Times</td>
    <td class="ContentText">Error Description</td>
  </tr>
  
  <?php  
     
mysql_select_db($database_SOLBEL, $SOLBEL);
$query_TECHS = "SELECT * FROM techs ORDER BY t_techid ASC";
$TECHS = mysql_query($query_TECHS, $SOLBEL) or die(mysql_error());
$row_TECHS = mysql_fetch_assoc($TECHS);
$totalRows_TECHS = mysql_num_rows($TECHS);



?>
    <tr>
      <td class="ContentTextSmall"><input name="ll_date[1]" type="text" size="10" /></td>
      <td class="ContentTextSmall"><select name="ll_tech[1]">
        <option selected="selected"></option>
		<?php do { ?>
		<option value="<?php echo $row_TECHS['t_techid']; ?>"><?php echo $row_TECHS['t_techid']; ?></option>
		<?php } while ($row_TECHS = mysql_fetch_assoc($TECHS)); ?>
      </select></td>
      <td class="ContentTextSmall"><input name="ll_code[1]" type="text" size="4" onChange="javascript:this.value=this.value.toUpperCase();" /></td>
      <td class="ContentTextSmall"><input name="ll_year[1]" type="text" size="2" value="06" />.<input name="ll_day[1]" type="text" size="3" /></td>
      <td class="ContentTextSmall"><input name="ll_time[1]" type="text" size="5" /></td>
      <td class="ContentTextSmall"><input name="ll_times[1]" type="text" size="2" /></td>
	  <td class="ContentTextSmall"><input name="lmc_desc[1]" type="text" size="75" /></td>
    </tr>
	  <?php
	mysql_free_result($TECHS);
	 ?>
Anyone ? Anyone ?

Thanks up front!

PinkFloyd
arukomp
Forum Contributor
Posts: 113
Joined: Sun Sep 24, 2006 4:22 am

Post by arukomp »

I don't really know what do you want, but maybe this could help:

First, gather information about existing errors into a php string, like $error_description
Second, in <input> tag, where you want to display that error, insert this:

value="<?php echo $error_description; ?>"

Now <input> tag should look similar to this:

Code: Select all

<input name="lmc_desc[1]" type="text" size="75" value="<?php echo $error_description; ?>" />
I hope this helped you a bit ;)
PinkFloyd
Forum Newbie
Posts: 3
Joined: Tue Dec 19, 2006 7:45 am

Post by PinkFloyd »

Hmm, yeah, well, I've got like thousands of error descriptions here... All tucked away in the database... So I don't think that's going to be an option...

But thanks anyway!
Post Reply