|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I've created a workorder tracking web application with Perl/Mysql that uses 2 Mysql tables: One that keeps the information on each workorder, and one that stores the information about each person in our organization.
Right now, you must type in the requestor of the workorder by hand. This is bad because it can cause misspelled names to generate a broken link to their contact information. What I want is a way to query Mysql OnChange of the requestor text field to automatically fill in the correct name from the people database. I want to avoid submitting the form and then returning the message "Requestor not found, please retype". Is there a way to query onchange of a text field and fill in the field based on information from the table? I hope this makes sense. |
|
#2
|
|||
|
|||
|
If you're suggesting that you want to use some kind of JavaScript to query the database, then I'm afraid you're SOL -- JavaScript being on the client side, it can't create a connection to the DB. However, you have a couple of options to kludge round it. In your Perl, query out the names of all employees and whack them into a JavaScript array in the generated page. Then, when people type in a name validate against that. If you don't want people to have to type in names, instead populate a drop down list. Here's a spot of sample code for the latter:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> use DBI; my $dbh = DBI->connect('DBI:mysql:mydb', $user, $pass, { RaiseError => 1 } ); my $sth = $dbh->prepare( 'SELECT emp_name FROM emp' ); $sth->execute; print '<SELECT name="employees">'; while( my ($emp) = $sth->fetchrow_array ) { print "<OPTION value="$emp">$emp"; } $sth->finish; $dbh->finish; [/code] That'll print you out a little snippet of HTML code (once you fix any syntax/semantic errors I've undoubtedly got in there, and have put in the correct names for your tables!). |
|
#3
|
|||
|
|||
|
Thanks Chris. I use your method for the drop down boxes - query the db to populate the boxes for some other fields but I'll have to use the Javascript array way though because there are 500+ options for the requestor field.
|
|
#4
|
|||
|
|||
|
Hey I got it working with the Javascript array way
Excellent |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > querying Mysql on change of text input |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|