...

View Full Version : onChange = "this.form.submit()"



sp!d3rm@n
12-17-2003, 04:25 PM
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...


<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

Kylena
12-18-2003, 08:59 AM
Is this a button or a dropdown?

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


onClick="this.form.submit()"

it doesn't do anything?

On 2nd thought, maybe this should be posted in the PHP forum?

Roelf
12-18-2003, 09:35 AM
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

sp!d3rm@n
12-18-2003, 04:10 PM
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 :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum