Alter Form values before submission

J

Jeremy

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 "(e-mail address removed)" 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
"(e-mail address removed)", 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>
 
L

Lee

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 "(e-mail address removed)" 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
"(e-mail address removed)", 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top