#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Walla Walla, WA
    Posts
    3
    Rep Power
    0
    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. #2
  3. No Profile Picture
    christucker
    Guest
    Devshed Newbie (0 - 499 posts)
    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!).
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Walla Walla, WA
    Posts
    3
    Rep Power
    0
    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.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Walla Walla, WA
    Posts
    3
    Rep Power
    0
    Hey I got it working with the Javascript array way
    Excellent

Similar Threads

  1. help with tables and wordwrapping
    By junkedBrian613 in forum PHP Development
    Replies: 2
    Last Post: February 15th, 2004, 06:42 PM
  2. input text : can an input text send 2 value
    By dbosz in forum PHP Development
    Replies: 1
    Last Post: January 28th, 2004, 06:41 AM
  3. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 07:19 PM
  4. float question
    By yeah-yeah in forum HTML Programming
    Replies: 10
    Last Post: January 15th, 2004, 04:59 PM
  5. Replies: 0
    Last Post: December 30th, 2003, 01:57 PM

IMN logo majestic logo threadwatch logo seochat tools logo