Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Which control changed?

Reply
Thread Tools

Which control changed?

 
 
Steve Swift
Guest
Posts: n/a
 
      11-15-2007
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?

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
 
Reply With Quote
 
 
 
 
Julien
Guest
Posts: n/a
 
      11-15-2007
On Nov 15, 10:17 am, Steve Swift <(E-Mail Removed)> wrote:
> 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/cgiContouri...touring.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






 
Reply With Quote
 
 
 
 
Steve Swift
Guest
Posts: n/a
 
      11-15-2007
Julien wrote:
> ...
> 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.

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing USER CONTROL which is inside Masterpagethrough Another USER Control inside normal page. Kiran More ASP .Net Web Controls 2 11-14-2006 12:58 PM
Accessing values of a control which is in a user control =?Utf-8?B?U3Jpbmk=?= ASP .Net 1 11-02-2006 08:53 AM
Microcontrollers: which one ? which language ? which compiler ? The Jesus of Suburbia NZ Computing 2 02-11-2006 06:53 PM
Compilation fails when a windows form user control is assigned a strong name but it refers to an activex control which does not have strong name ashish_gokhale ASP .Net Web Controls 0 05-05-2005 01:38 PM
Compilation failed while compling window user control which takes reference of Activex control ashish_gokhale ASP .Net 0 05-05-2005 01:36 PM



Advertisments