Alter Form values before submission

Discussion in 'Javascript' started by Jeremy, Nov 17, 2005.

  1. Jeremy

    Jeremy Guest

    Hi All. I'm hoping I can receive some help from some kind soul. I was

    flamed for asking this question elsewhere. In the example below, I have

    removed references to the actual domain I'm working on, but this
    doesn't change the concept.


    I'm trying to create a client-side event that will run when the user
    submits a form. I want them to be able to enter a value for USERID
    that will either be "" or just "joe." the trick is
    making the form accept either of them.


    If the value is just "joe" don't do anything to it, and just pass it to

    the server and if the value is
    "", strip the "@domain.com" before submitting it.


    Here's something that I thought might work, but didn't. Any guru that
    could whip something up would be really appreciated. Thanks in
    advance!


    <SCRIPT TYPE="text/javascript">
    <!--
    // This will remove the ' @domain.com' part, (leaving just "joe")
    before submitting the form.
    //
    function WackTheDomain()
    {
    if ( (USERID contains "@domain.com") )
    USERID = USERID -"domain.com";
    else
    USERID = USERID;
    }

    // -->
    </SCRIPT>

    <FORM NAME="LOGIN" AUTOCOMPLETE="OFF" METHOD="POST"
    ACTION="https://form.domain.com" onSubmit="return WackTheDomain()">


    User Name <INPUT TYPE="TEXT" id ="USERID" NAME ="USERID"
    VALUE=""><p>&nbsp;</p>
    Password <INPUT TYPE="PASSWORD" id ="PASSWORD" NAME ="PASSWORD"
    VALUE="">
    <p>&nbsp;</p>
    <p>


    <INPUT TYPE="SUBMIT" id ="SUBMIT" NAME ="SUBMIT" alt = "Submit The
    Form" >
    <INPUT TYPE="HIDDEN" id ="ACTION" NAME ="ACTION" VALUE="LOGIN">


    </p>
    </FORM>
     
    Jeremy, Nov 17, 2005
    #1
    1. Advertising

  2. Jeremy

    Lee Guest

    Jeremy said:
    >
    >Hi All. I'm hoping I can receive some help from some kind soul. I was
    >
    >flamed for asking this question elsewhere. In the example below, I have
    >
    >removed references to the actual domain I'm working on, but this
    >doesn't change the concept.
    >
    >
    >I'm trying to create a client-side event that will run when the user
    >submits a form. I want them to be able to enter a value for USERID
    >that will either be "" or just "joe." the trick is
    >making the form accept either of them.
    >
    >
    >If the value is just "joe" don't do anything to it, and just pass it to
    >
    >the server and if the value is
    >"", strip the "@domain.com" before submitting it.
    >
    >
    >Here's something that I thought might work, but didn't. Any guru that
    >could whip something up would be really appreciated. Thanks in
    >advance!
    >
    >
    ><SCRIPT TYPE="text/javascript">
    ><!--
    >// This will remove the ' @domain.com' part, (leaving just "joe")
    >before submitting the form.
    >//
    >function WackTheDomain()
    >{
    >if ( (USERID contains "@domain.com") )
    >USERID = USERID -"domain.com";
    >else
    >USERID = USERID;
    >}
    >
    >// -->
    ></SCRIPT>
    >
    ><FORM NAME="LOGIN" AUTOCOMPLETE="OFF" METHOD="POST"
    >ACTION="https://form.domain.com" onSubmit="return WackTheDomain()">
    >
    >
    >User Name <INPUT TYPE="TEXT" id ="USERID" NAME ="USERID"
    >VALUE=""><p>&nbsp;</p>
    >Password <INPUT TYPE="PASSWORD" id ="PASSWORD" NAME ="PASSWORD"
    >VALUE="">
    ><p>&nbsp;</p>
    ><p>
    >
    >
    ><INPUT TYPE="SUBMIT" id ="SUBMIT" NAME ="SUBMIT" alt = "Submit The
    >Form" >
    ><INPUT TYPE="HIDDEN" id ="ACTION" NAME ="ACTION" VALUE="LOGIN">
    >
    >
    ></p>
    ></FORM>
    >


    In the future, don't try guessing about what might work.
    Get rid of the <SCRIPT> block, completely.
    Change your onsubmit value:

    onsubmit="USERID.value=USERID.value.replace(/@domain.com/,'')"

    Although it would be better to fix your server-side code so that this sort of
    change happens there, instead.
     
    Lee, Nov 17, 2005
    #2
    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. Alter Values in ListBox

    , Jan 8, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    347
  2. Brian Simmons
    Replies:
    2
    Views:
    699
    Brian Simmons
    Jul 19, 2007
  3. Logical

    Modifying form data before submission

    Logical, Jul 25, 2003, in forum: Javascript
    Replies:
    1
    Views:
    195
    Chris Wright
    Jul 25, 2003
  4. john
    Replies:
    0
    Views:
    104
  5. -berlin.de
    Replies:
    0
    Views:
    161
    -berlin.de
    Jun 30, 2007
Loading...

Share This Page