Which control changed?

S

Steve Swift

I don't have a particular webpage to point you to; I thought about this
whilst walking my dog this morning and don't have an example page. That
said, this question doesn't really require a "working" example.

I have a form with two <SELECT> controls. Both contain:
onChange="this.form.submit()"

So whichever one changes, my POST data contains both elements. How can I
know which one changed?

My idea is to include this in the form:
<INPUT TYPE=HIDDEN NAME=CONTROL VALUE="">

Then to change each onChange to something like this:
onChange="this.form.CONTROL.value='CONTROL_A';this.form.submit()"
where I'd use the name of the control in place of CONTROL_A of course.

So now I'll have an additional "CONTROL" value in my POST data telling
me which control changed.

Is this a workable solution? Is there a better way of doing things?
 
J

Julien

I don't have a particular webpage to point you to; I thought about this
whilst walking my dog this morning and don't have an example page. That
said, this question doesn't really require a "working" example.

I have a form with two <SELECT> controls. Both contain:
onChange="this.form.submit()"

So whichever one changes, my POST data contains both elements. How can I
know which one changed?

My idea is to include this in the form:
<INPUT TYPE=HIDDEN NAME=CONTROL VALUE="">

Then to change each onChange to something like this:
onChange="this.form.CONTROL.value='CONTROL_A';this.form.submit()"
where I'd use the name of the control in place of CONTROL_A of course.

So now I'll have an additional "CONTROL" value in my POST data telling
me which control changed.

Is this a workable solution? Is there a better way of doing things?

Hi Steve!

There is a better way. You could just set a variable and change the
"action" string for your form.

In the header of your document, put something like:
<script language="text/javascript"><!--
var changedSelect = '';
var programToCall = "/someProgram.exe";
function SetActionString() {
actionString = programToCall + "?" + changedSelect;
return actionString;
}
</script>

In the body of your document, put something like:
<form id="aForm">
<select id="first"
onChange="document.changedSelect=this.id;document.forms['aForm'].action=SetActionString();">
<select id="second"
onChange="document.changedSelect=this.id;document.forms['aForm'].action=SetActionString();">

Not tested and improving code still possible, but the idea is above.

The name of the changed select box will be passed to in the
QUERY_STRING environment variable that you can read server side, this
even if your form is submitted via "POST".

I use similar technique to pass the language in forms that are sent in
POST mode.
Have a look at http://www.altipoint.com/cgiContouring/docContouring.en.htm
to see.
This is a webservice available in 4 languages. Using the query string
let me know from step to step in which language to display the text.

Julien
 
S

Steve Swift

Julien said:
...
The name of the changed select box will be passed to in the
QUERY_STRING environment variable that you can read server side, this
even if your form is submitted via "POST".

Thanks, I'll take a look at that mechanism. I'm not expert at reading
JavaScript, so I'll have fun working out how it operates; it doesn't
look too difficult for me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top