PDA

View Full Version : Using onChange to submit a <SELECT> form


Uncle Ron
01-08-2003, 04:38 PM
The site I am working on is an intranet that allows the user to make changes to their own data. First they select one of their customers (called GROUPs). The balance of the form is filled in from the data base. Then the user can make any changes needed and update the data base.

Currently the user selects from a list of their customers and clicks on a "GET GROUP" button which uses CGI/PERL to retrieve the data. I would like to eliminate the need to click on the "GET GROUP" button and have the selection process fire an onChange event that will submit the form so the PERL script can execute.


Although I'm perfectly capable with PERL and CGI and of course HTML, I'm very limited using JavaScript. Here is what I've tried.

function getGroup()
{form.submit(document.forms[0].elements[0].value);}

I will mention that the <OPTION>(s) of the <SELECT> tag are loaded dynamically with a PERL script. And during my testing I substituted ALERT for FORM.SUBMIT and I get the correct value, but can't seem to get it to submit the form.

Thanks in advance for any help.
UR

beetle
01-08-2003, 05:35 PM
<select onchange="this.form.submit();">
<!-- options -->
</select>

arnyinc
01-08-2003, 05:35 PM
Is the "GET GROUP" button just a submit button? In that case, all you have to do is find out when the users changes the select box and submit your form based on that.


<form name="your_form_name" method="post" action="lookup.pl">
<select onchange="document.your_form_name.submit()">
<option>...
</select>
</form>

cg9com
01-08-2003, 05:37 PM
heres what i do, <edit>beetles seems to be the best opton.</edit>
onChange="location=options[selectedIndex].value;">

cg9com
01-08-2003, 05:38 PM
WOW did the 3 of us post at the same time????

Uncle Ron
01-08-2003, 06:06 PM
AMAZING. You people are wonderful. I have to rush out right now. But, as Arnold says, I'll be back. And of course try the answer. I'll let you all know.

Thanks

UR:)

Uncle Ron
01-09-2003, 01:30 AM
Thanks for waiting. I'm back and I tried out beetle's code. It worked, that's for sure. But now this. My ignorance JavaScript is showing.

Here is what I do with the script. The form is passed to a cgi script called masterFiles that handles all the master file updates. The submit buttons have values that are passed back to the script when they are activated. The masterFiles script allows for three submit parameters which are $update1, $update2, $exit. If the button exists and is activiated then a non-null value is set.

So, when the request to retreive a record from the data base is made $update2 is set non-null, and the script is requested. This is the same script that was requested in the first place. In other words ONLY masterFiles.cgi is used. This script retreives and updates data from the files, as well as handling the forms. The only way to exit masterFiles.cgi is by making sure $exit variable is non-null.

I'm hoping this makes sense, because I can now see I needed to do two things. One is causing the onChange to submit the form (and that's done, thank-you all very much). Two is to be able to make $update2 a non-null variable. Is this possible?

UR:confused: but very hopeful!