Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onChange = "this.form.submit()"

    I'm having a problem integrating a javascript form with a php/mysql database. I'm a newbie at javascript so please consider this as you read what might be a stupid question...

    I have a form that the user needs to fill out with redundant data so I have created a dynamic drop down box to act as a time saver allowing the fields to propogate through the form once the proper ID is selected. The drop down works and when selected propogates the neccessary information but with a catch, here's the code...
    PHP Code:
    <select size="1" name="phid" onChange="this.form.submit()">
        <?
        
    // GET Pharmacy ID's by Territory
        
    $query "SELECT Ph_ID, Pharmacy_Name FROM pharmacies WHERE terr_ID='$SESSION_TERR_ID'";
        
    $result mysql_db_query($database$query$connection) or die ("Error in query: $query. " mysql_error());
        while (list(
    $Ph_ID$Pharmacy_Name) = mysql_fetch_row($result))
            {
                echo 
    "<option value='$Ph_ID'>$Ph_ID</option>";
            }
        
    ?></select>
    simple right? when the appropriate drop down is selected the code elsewhere on the page <? echo's ?> the proper result. Now I fill in the rest of the information in the adjoining fields and hit submit.

    The submit() function overrides the <input> that is supposed to carry all the variables to the next page to be submitted to the database.

    Is there another way to use the dropdown box and still use a submit button without them cancelling one another out?

    I've attached the code for your viewing pleasure... All help would be appreciated
    Attached Files Attached Files

  • #2
    New Coder
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is this a button or a dropdown?

    If it's just a button, when you put in the code:

    Code:
    onClick="this.form.submit()"
    it doesn't do anything?

    On 2nd thought, maybe this should be posted in the PHP forum?
    Last edited by Kylena; 12-18-2003 at 09:01 AM.

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    the select is not inside a from, you have:
    <form action="add_sum.php" method="submit">
    </form>

    on your page, the select is defined after that
    I am the luckiest man in the world

  • #4
    New to the CF scene
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I figured it out... here's the scoop.

    I have two forms on the page... the first form submits data (javascript form with the onChange option) and the second form takes all the data generated by the first form with additional data and submits it to the database.

    I had a form within a form when I should have had the forms in tandem. The first form selects all the data through a php/javascript hybrid <select> with the form name="selectphid".

    The second form posts to a script called add_sum.php.

    It works now. And if you think you're confused now try writing the code in the first place

    Thanks for all that replied to this post


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •