Which control changed?

Discussion in 'Javascript' started by Steve Swift, Nov 15, 2007.

  1. Steve Swift

    Steve Swift Guest

    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
    Steve Swift, Nov 15, 2007
    #1
    1. Advertising

  2. Steve Swift

    Julien Guest

    On Nov 15, 10:17 am, Steve Swift <> 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/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
    Julien, Nov 15, 2007
    #2
    1. Advertising

  3. Steve Swift

    Steve Swift Guest

    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
    Steve Swift, Nov 15, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Larsson
    Replies:
    0
    Views:
    264
    Peter Larsson
    Mar 9, 2005
  2. Replies:
    1
    Views:
    671
    Rosanne
    Oct 11, 2005
  3. =?Utf-8?B?RGFuIFNpa29yc2t5?=

    HOWTO: Know Which Controls Actually Changed Values On FormView

    =?Utf-8?B?RGFuIFNpa29yc2t5?=, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    283
    Cowboy \(Gregory A. Beamer\)
    Oct 6, 2006
  4. Neal Becker

    pickle/unpickle class which has changed

    Neal Becker, Mar 6, 2012, in forum: Python
    Replies:
    4
    Views:
    321
    Peter Otten
    Mar 6, 2012
  5. mxbrunet
    Replies:
    1
    Views:
    202
Loading...

Share This Page