Multiple forms and Multiple submit buttons and validation

Discussion in 'Javascript' started by sandyde2, Oct 1, 2003.

  1. sandyde2

    sandyde2 Guest

    Hi all,

    I get the tough problem and expect to get help..

    In a html page, I dynamically created many forms which named as
    NO+business_id. In each form there are two submit buttons to
    "release_or_not". of course in the server side I validate those values
    as well. However, because this page is for admin to use so that I do
    not need to care any hacker action. Hence, in the client side
    javascript I validate those values and give it a popup report window
    to confirm.

    Now the problem comes. The javascript does not know which button I
    clicked. Therefore I make a onclick function in setAction
    <input type="submit" value="Release" name="release_or_not"
    onClick="return setAction(1)">
    <input type="submit" value="Reject + Delete Entry"
    name="release_or_not" onClick="return setAction(2)">
    and a hidden variable called ddd
    <input type="hidden" name="ddd" value="" >

    after clicking a submit button, it calles the setAction function
    before onsubmit isValid function of the form. In setAction function, I
    want to set the hidden ddd variable to "Release" or "Reject + Delete
    Entry", so that it is the alternative way for the validation function
    to know which submit button I clicked.
    function setAction(act)
    {
    if(act == 1)
    {
    x.ddd.value = "Release";
    return true;
    }
    else if(act == 2)
    {
    x.ddd.value = "Reject + Delete Entry";
    return true;
    }
    else
    {
    return false;
    }
    }

    as you see, currently I do not know in which form it is. I ever create
    the setAction(this,1).. and expect "this" can be the form.. but
    failed..

    I have no idea now.. any comment will be greatly appreciated..

    with best wishes

    sandy
     
    sandyde2, Oct 1, 2003
    #1
    1. Advertising

  2. sandyde2

    Lee Guest

    sandyde2 said:

    >as you see, currently I do not know in which form it is. I ever create
    >the setAction(this,1).. and expect "this" can be the form.. but
    >failed..


    Since setAction(this,1) is in the onClick handler of the submit button,
    the "this" refers to the button. Fortunately, every form element has
    an attribute named "form" which is a reference to the form which
    contains it:

    setAction(this.form,1)
     
    Lee, Oct 1, 2003
    #2
    1. Advertising

  3. sandyde2

    sandyde2 Guest

    Thanks, Lee !

    You are sooo helpful !! Now the question solved ! :D

    with best wishes

    sandy



    Lee <> wrote in message news:<>...
    > sandyde2 said:
    >
    > >as you see, currently I do not know in which form it is. I ever create
    > >the setAction(this,1).. and expect "this" can be the form.. but
    > >failed..

    >
    > Since setAction(this,1) is in the onClick handler of the submit button,
    > the "this" refers to the button. Fortunately, every form element has
    > an attribute named "form" which is a reference to the form which
    > contains it:
    >
    > setAction(this.form,1)
     
    sandyde2, Oct 2, 2003
    #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. The Crow
    Replies:
    2
    Views:
    4,462
    Bruce Barker
    Sep 27, 2005
  2. Replies:
    12
    Views:
    782
    Debbie
    Apr 17, 2006
  3. Replies:
    4
    Views:
    1,014
  4. Milton

    Validation when there are two submit buttons

    Milton, Jan 18, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    128
    Milton
    Jan 18, 2005
  5. Harry
    Replies:
    3
    Views:
    395
    Harry
    Jan 12, 2006
Loading...

Share This Page