By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,817 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,817 IT Pros & Developers. It's quick & easy.

help with onclick submit

P: n/a
In an unnamed form, unnamed because it only submits an email address, I'm
trying to have the submit button clear the "e-mail" text value in the
textbox.

On the submit button I have the following:

onClick="if(this.form['e-mail'].value=='e-mail')this.form['e-mail'].value=''"

But it does not seem to work. Any ideas or suggestions?

Thanks in advance!
Sep 28 '05 #1
Share this Question
Share on Google+
16 Replies


P: n/a

John wrote:
In an unnamed form, unnamed because it only submits an email address, I'm
trying to have the submit button clear the "e-mail" text value in the
textbox.

On the submit button I have the following:

onClick="if(this.form['e-mail'].value=='e-mail')this.form['e-mail'].value=''"

But it does not seem to work. Any ideas or suggestions?

Thanks in advance!


You are accessing the form elements incorrectly. Try the following
instead:

this.form.elements['e-mail'].value

Sep 28 '05 #2

P: n/a

"web.dev" <we********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...

You are accessing the form elements incorrectly. Try the following
instead:

this.form.elements['e-mail'].value


Thanks but it does not seem to work.

This here works:

<input type="text" name="email" value="e-mail"
onClick="if(this.value=='e-mail')this.value=''">

Then right below I have the line for my submit button as per your
suggestion:

<input type="submit" value="Go!"
onClick="if(this.form.elements['e-mail'].value=='e-mail')this.form.elements['e-mail'].value=''">

Unfortunately it's not working.

Any other ideas?

Thanks!
Sep 28 '05 #3

P: n/a

John wrote:
"web.dev" <we********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...

You are accessing the form elements incorrectly. Try the following
instead:

this.form.elements['e-mail'].value


Thanks but it does not seem to work.

This here works:

<input type="text" name="email" value="e-mail"
onClick="if(this.value=='e-mail')this.value=''">

Then right below I have the line for my submit button as per your
suggestion:

<input type="submit" value="Go!"
onClick="if(this.form.elements['e-mail'].value=='e-mail')this.form.elements['e-mail'].value=''">

Unfortunately it's not working.

Any other ideas?

Thanks!


Sorry for the confusion, when you first posted I had thought the name
of your input element was "e-mail". Try the same solution this time
replacing 'e-mail' with 'email':

this.form.elements['email'].value

Sep 28 '05 #4

P: n/a

"web.dev" <we********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

Sorry for the confusion, when you first posted I had thought the name
of your input element was "e-mail". Try the same solution this time
replacing 'e-mail' with 'email':

this.form.elements['email'].value


Thanks but it's still not working...

Sep 28 '05 #5

P: n/a

John wrote:
"web.dev" <we********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

Sorry for the confusion, when you first posted I had thought the name
of your input element was "e-mail". Try the same solution this time
replacing 'e-mail' with 'email':

this.form.elements['email'].value


Thanks but it's still not working...


The current action is still submitting the form. The onClick even
expects a boolean value to be returned. To see the expected result you
are looking for, do the following:

<input type="submit" value="Go!"
onClick="if(this.form.elements['email'].value=='email'){this.form.elements['email'].value='';}
return false;">

Sep 28 '05 #6

P: n/a

"web.dev" <we********@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...

The current action is still submitting the form. The onClick even
expects a boolean value to be returned. To see the expected result you
are looking for, do the following:

<input type="submit" value="Go!"
onClick="if(this.form.elements['email'].value=='email'){this.form.elements['email'].value='';}
return false;">


Thanks, it makes sense, but it's still not working. I tried changing the
value from email to e-mail as that's the value in the previous statement is
but still nothing.
Sep 28 '05 #7

P: n/a
John wrote:
In an unnamed form, unnamed because it only submits an email address, I'm
trying to have the submit button clear the "e-mail" text value in the
textbox.

On the submit button I have the following:

onClick="if(this.form['e-mail'].value=='e-mail')this.form['e-mail'].value=''"

But it does not seem to work. Any ideas or suggestions?

What do you expect to happen when you click the submit button? You want
to submit the email value, don't you?
Mick
Sep 28 '05 #8

P: n/a
Lee
web.dev said:


John wrote:
"web.dev" <we********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
>
> Sorry for the confusion, when you first posted I had thought the name
> of your input element was "e-mail". Try the same solution this time
> replacing 'e-mail' with 'email':
>
> this.form.elements['email'].value
>


Thanks but it's still not working...


The current action is still submitting the form. The onClick even
expects a boolean value to be returned. To see the expected result you
are looking for, do the following:

<input type="submit" value="Go!"
onClick="if(this.form.elements['email'].value=='email'){this.form.elements['email'].value='';}
return false;">


Better:

Never, ever, use the onclick handler of a submit button.
Use the onsubmit handler of the form tag, instead.

Sep 28 '05 #9

P: n/a

"Mick White" <mw***********@rochester.rr.com> wrote in message
news:hn*****************@twister.nyroc.rr.com...

What do you expect to happen when you click the submit button? You want
to submit the email value, don't you?
Mick


Yes, but not if the email value == the initial value "e-mail"

In other words, I don't want an email address called "e-mail" to be
submitted so, so when they try to hit submit, the words "e-mail" go away
from the textfield.
Sep 28 '05 #10

P: n/a

"Lee" <RE**************@cox.net> wrote in message
news:dh*********@drn.newsguy.com...

Better:

Never, ever, use the onclick handler of a submit button.
Use the onsubmit handler of the form tag, instead.


Only problem with that is that the user never sees the text "e-mail"
disappear if it has to be submitted. Rather, I'd want them to see the text
disappear when they click on the submit button.This way, if the form is
submitted, then a blank address gets emailed instead of "email" being
submitted as an email address.
Sep 28 '05 #11

P: n/a
ASM
John a écrit :
"web.dev" <we********@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...

<input type="submit" value="Go!"
onClick="if(this.form.elements['email'].value=='email'){this.form.elements['email'].value='';}
return false;">


Thanks, it makes sense, but it's still not working. I tried changing the
value from email to e-mail as that's the value in the previous statement is
but still nothing.


<form action="foo.htm"
onsubmit="if(this.email.value=='e-mail'){
this.email.value='';
return false;
}
else
return true;">
<input type=text name="email" value="e-mail">
<input type=submit value=GO>
</form>

--
Stephane Moriaux et son [moins] vieux Mac
Sep 28 '05 #12

P: n/a
Lee
John said:


"Lee" <RE**************@cox.net> wrote in message
news:dh*********@drn.newsguy.com...

Better:

Never, ever, use the onclick handler of a submit button.
Use the onsubmit handler of the form tag, instead.


Only problem with that is that the user never sees the text "e-mail"
disappear if it has to be submitted. Rather, I'd want them to see the text
disappear when they click on the submit button.This way, if the form is
submitted, then a blank address gets emailed instead of "email" being
submitted as an email address.


Well, if you're not actually submitting anything, don't freaking use
a submit button. Use a regular button.

Sep 28 '05 #13

P: n/a

"Lee" <RE**************@cox.net> wrote in message
news:dh********@drn.newsguy.com...
Well, if you're not actually submitting anything, don't freaking use
a submit button. Use a regular button.


It *is* submitting something, an email address. But if the email address is
"email" I want it blank.
Sep 29 '05 #14

P: n/a

"ASM" <st*********************@wanadoo.fr.invalid> wrote in message
news:43**********************@news.wanadoo.fr...

<form action="foo.htm"
onsubmit="if(this.email.value=='e-mail'){
this.email.value='';
return false;
}
else
return true;">
<input type=text name="email" value="e-mail">
<input type=submit value=GO>
</form>

Thanks! :-)
Sep 30 '05 #15

P: n/a
Lee
John said:


"Lee" <RE**************@cox.net> wrote in message
news:dh********@drn.newsguy.com...
Well, if you're not actually submitting anything, don't freaking use
a submit button. Use a regular button.


It *is* submitting something, an email address. But if the email address is
"email" I want it blank.


If you're submitting, and you want something to happen first, and/or
you want the submission to be cancelled under certain circumstances,
then use the onsubmit handler of the form. Do NOT use the onclick
handler of the submit button.

Sep 30 '05 #16

P: n/a
ASM wrote on 29 sep 2005 in comp.lang.javascript:
<form action="foo.htm"
onsubmit="if(this.email.value=='e-mail'){
this.email.value='';
return false;
}
else
no need for the else here!
return true;">
<input type=text name="email" value="e-mail">
<input type=submit value=GO>
</form>


even shorter is:

onsubmit="
if(this.email.value!='e-mail')
return true;
this.email.value='';
return false;"
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Sep 30 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.