Multiple onclick=submit() need to pass name????

Discussion in 'Javascript' started by charlie_M, May 16, 2005.

  1. charlie_M

    charlie_M Guest

    I have a number of applications where I want to have many
    onclick='submit()' attached to different 'elements' on a single form
    ..... which sends the form to a CGI "script" which does all the
    validation. The problem is.. how can I code the submit()s so the CGI's
    form collection knows which 'element' was clicked??

    I am NOT permitted to use <input type=image...> or any "button" that
    browsers produce for forms.... the reasons are all client related
    ;o)))

    If I can put a string inside the parentheses (i.e.
    onclick='submit("thisbutton")'.... and have it's characters included in
    the POST information to the CGI.. It will work for me. Can this be
    done?? how?
    charlie_M, May 16, 2005
    #1
    1. Advertising

  2. charlie_M

    Lee Guest

    charlie_M said:
    >
    >I have a number of applications where I want to have many
    >onclick='submit()' attached to different 'elements' on a single form
    >.... which sends the form to a CGI "script" which does all the
    >validation. The problem is.. how can I code the submit()s so the CGI's
    >form collection knows which 'element' was clicked??
    >
    >I am NOT permitted to use <input type=image...> or any "button" that
    >browsers produce for forms.... the reasons are all client related
    >;o)))
    >
    >If I can put a string inside the parentheses (i.e.
    >onclick='submit("thisbutton")'.... and have it's characters included in
    >the POST information to the CGI.. It will work for me. Can this be
    >done?? how?


    1. It's your responsibility to point out to your clients that
    they're making a potentially serious mistake by not allowing
    the form to be submitted if Javascript is disabled.

    2.
    onclick="document.forms[0].myHiddenField.value='thisButton';document.forms[0].submit()"
    Lee, May 16, 2005
    #2
    1. Advertising

  3. charlie_M

    Randy Webb Guest

    charlie_M wrote:
    > I have a number of applications where I want to have many
    > onclick='submit()' attached to different 'elements' on a single form
    > ..... which sends the form to a CGI "script" which does all the
    > validation. The problem is.. how can I code the submit()s so the CGI's
    > form collection knows which 'element' was clicked??
    >
    > I am NOT permitted to use <input type=image...> or any "button" that
    > browsers produce for forms.... the reasons are all client related
    > ;o)))
    >
    > If I can put a string inside the parentheses (i.e.
    > onclick='submit("thisbutton")'.... and have it's characters included in
    > the POST information to the CGI.. It will work for me. Can this be
    > done?? how?
    >


    onclick="someFunction(this.id)"

    <input type="text" name="inputUsed">

    function someFunction(inputID){
    document.forms['formName'].elements['inputUsed'].value = inputID;
    document.forms['formName'].submit();
    }

    And in each of your "elements" have an ID attribute that identifies it.

    In other words, instead of using the element to submit the form, have
    the element give a function its ID attribute, set a form field to that
    value, then submit the form. Then, the server can pick up the value of
    inputUsed to determine what element was used to submit the form.

    And I won't go into the ludicrous idea of setting up a webpage the way
    you are describing. If your client is that ignorant, its *your* job as
    the professional to educate them on the pitfalls of the design.
    Accessibility, non-JS, and many other issues make the entire approach a
    bad design before you have ever started.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Randy Webb, May 16, 2005
    #3
  4. charlie_M

    charlie_M Guest

    OK.. 2 things I do not understand...

    1. If I (as the CGI) receive an ID.. how do I know WHICH submit() it
    was ?? Knowing that it was ID #5 tells me what??? This occured to me in
    browsing other people's posts about this and similar topics. I need to
    pass a NAME and somehow have it included in the form data return. The
    CGI can then figure it out.

    2. How do I get the form's data to be submitted with the form data and
    the id(s)?? From your example. I think I see how this is done. Can
    this be used more simply??? .... I only ever have 1 form... like???

    function someFunction(NameNotId){
    thisform.elements['NameNotId'].value = 'XX';
    thisform.submit();
    }

    I am only 'guessing' about the 'thisform' syntax..... does this work??

    TIA
    Chuck
    charlie_M, May 16, 2005
    #4
  5. charlie_M

    charlie_M Guest

    You are right Lee.... and I have. These applications are very complex
    and the client has a bug in his butt about looking a "paricular way"
    and javascript must serve. The apps are written in Visual Fox and run
    on a PC based blade server. We can not change how the server side works
    and M$'s buttons and Netscape buttons are abhorent to the client, I am
    attempting to get a <TD> to work as a submit button with appropriate
    stylesheet colorings and rollovers. These are not public access apps...
    they are for logged-in publishers and the ilk and we get to say how
    they access the app!!!

    Thanks
    Chuck
    charlie_M, May 16, 2005
    #5
  6. charlie_M

    Randy Webb Guest

    charlie_M wrote:

    > OK.. 2 things I do not understand...
    >
    > 1. If I (as the CGI) receive an ID.. how do I know WHICH submit() it
    > was ?? Knowing that it was ID #5 tells me what??? This occured to me in
    > browsing other people's posts about this and similar topics. I need to
    > pass a NAME and somehow have it included in the form data return. The
    > CGI can then figure it out.


    Pass the name itself.

    <input type="button" name="button1" value="Button Number 1"
    onclick="someFunction(this.name)">

    function someFunction(elemName){
    myForm = document.forms['formName'];
    myForm.elements['fieldName'].value = elemName;
    myForm.submit();
    }

    Then, the server looks at the value of the field named "fieldName" and
    it will know the name of the element that was clicked to submit the
    form. Test it :)

    > 2. How do I get the form's data to be submitted with the form data and
    > the id(s)?? From your example. I think I see how this is done. Can
    > this be used more simply??? .... I only ever have 1 form... like???
    >
    > function someFunction(NameNotId){
    > thisform.elements['NameNotId'].value = 'XX';
    > thisform.submit();
    > }
    >
    > I am only 'guessing' about the 'thisform' syntax..... does this work??


    Only in IE if the name of the form is thisform. See above.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Randy Webb, May 17, 2005
    #6
  7. charlie_M

    Grant Wagner Guest

    "charlie_M" <> wrote in message
    news:...
    > OK.. 2 things I do not understand...
    >
    > 1. If I (as the CGI) receive an ID.. how do I know WHICH submit() it
    > was ?? Knowing that it was ID #5 tells me what??? This occured to me
    > in
    > browsing other people's posts about this and similar topics. I need to
    > pass a NAME and somehow have it included in the form data return. The
    > CGI can then figure it out.


    Don't rely on client-side JavaScript at all:

    <%
    Response.write(Request.value('a1') + ';' + Request.value('d1'));
    %>
    <form>
    <input type="submit" name="a1" value="Add">
    <input type="submit" name="d1" value="Delete">
    </form>

    If I click -a1- I get Add:null, if I click -d1- I get null;Delete.

    It would be simple matter to loop on the server looking for a known
    input name that has a non-null value, then act on it... for safety you
    may want to pass another hidden input that contains the number
    of -a#-, -d#- items, otherwise you wouldn't know when to stop checking
    on the server.

    --
    Grant Wagner <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Grant Wagner, May 17, 2005
    #7
  8. charlie_M

    charlie_M Guest

    Grant..

    I stated earlier I cannot change how the server side works. Also... I
    cannot use any sort of BUTTON... i.e "<input type=submit...>

    It would be a VERY simple matter to catch the value if it were
    there.... but javascript.submit() does not automatically provide it ..
    which is why the "original" question was posed...........?????

    The ANSWER.. BTW has been implimented and it works with some
    limitations:

    onClick="document.forms[0].MYBUTTON.value='FLASHW';document.forms[0].submit()"

    which requires I supply a hidden variable in the form named "MYBUTTON"
    and my CGI will pickup on it if this submit() element is clicked.
    BTW... this "element" is simply a <TD> with stylesheet rollover-type
    elements..... and there are a number of them. This satisfies the
    client, looks really impressive, works like a charm, was the answer to
    the original question. ;o)))

    Thanks to all that contributed...
    Chuck
    charlie_M, May 18, 2005
    #8
  9. charlie_M wrote:

    > [...] M$'s buttons and Netscape buttons are abhorent to the client,


    Then use input[type="image"] elements and create your own buttons.
    I don't see a problem here, especially if it's not a "public app".

    > I am attempting to get a <TD> to work as a submit button with
    > appropriate stylesheet colorings and rollovers. [...]


    Why not format an input[type="submit"] that way?

    > [...]
    > !!


    Looks like you've lost something.


    PointedEars
    Thomas 'PointedEars' Lahn, May 23, 2005
    #9
  10. charlie_M

    charlie_M Guest

    Thomas 'PointedEars' Lahn wrote:
    > charlie_M wrote:
    >
    > > [...] M$'s buttons and Netscape buttons are abhorent to the client,

    >
    > Then use input[type="image"] elements and create your own buttons.
    > I don't see a problem here, especially if it's not a "public app".
    >
    > > I am attempting to get a <TD> to work as a submit button with
    > > appropriate stylesheet colorings and rollovers. [...]

    >
    > Why not format an input[type="submit"] that way?
    >
    > > [...]
    > > !!

    >
    > Looks like you've lost something.
    >
    >
    > PointedEars


    I don't know why your ears are pointed.. but your eyes are failing you
    ;o))

    REF: the original message says "I am NOT permitted to use <input
    type=image...> or any "button" that browsers produce for forms.... the
    reasons are all client related"... therefore: ??? The <TD> is what they
    wanted... and I posted the solution.

    Thanks
    Chuck
    charlie_M, May 24, 2005
    #10
  11. charlie_M wrote:
    <snip>
    > REF: the original message says "I am NOT permitted to
    > use <input type=image...> or any "button" that browsers
    > produce for forms.... the reasons are all client
    > related"... therefore: ??? The <TD> is what they
    > wanted... and I posted the solution.


    The 'therefor' is not valid. Experience suggests that such a requirement
    on the part of a client is usually the product of a misconception, or a
    lack of thought. And so it is usually an examination of the reasoning
    behind the requirement that exposes the real solution.

    Of course if the reasoning behind an apparently bad decision is never
    revealed then no useful progress can be made, but generally TD elements
    make very poor GUI components.

    Richard.
    Richard Cornford, May 25, 2005
    #11
  12. charlie_M wrote:

    > Thomas 'PointedEars' Lahn wrote:
    >> charlie_M wrote:
    >> > [...] M$'s buttons and Netscape buttons are abhorent to the client,

    >>
    >> Then use input[type="image"] elements and create your own buttons.
    >> I don't see a problem here, especially if it's not a "public app".
    >>
    >> > I am attempting to get a <TD> to work as a submit button with
    >> > appropriate stylesheet colorings and rollovers. [...]

    >>
    >> Why not format an input[type="submit"] that way?

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    >> [...]

    > [...]
    > REF: the original message says "I am NOT permitted to use <input
    > type=image...> or any "button" that browsers produce for forms.... the
    > reasons are all client related"... therefore: ??? The <TD> is what they
    > wanted...


    They only wanted it because they do not know better, and they certainly
    do not know that using `td' elements as controls will reduce the people
    in the target group and increase maintenance costs since support for
    client-side scripting is not guaranteed and neither is the required DOM
    support. It is your job to change that and if you do not do it, you
    behave incompetent (and deserve all what must follow in the mid-term
    and long-term).


    PointedEars
    --
    But he had not that supreme gift of the
    artist, the knowledge of when to stop.
    -- Sherlock Holmes
    Thomas 'PointedEars' Lahn, May 25, 2005
    #12
    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. Mark
    Replies:
    1
    Views:
    1,661
  2. Replies:
    4
    Views:
    885
  3. bob
    Replies:
    3
    Views:
    174
  4. Replies:
    2
    Views:
    240
  5. Replies:
    4
    Views:
    165
Loading...

Share This Page