Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / September 2005



Tip: Looking for answers? Try searching our database.

help with onclick submit

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 28 Sep 2005 21:28 GMT
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!
web.dev - 28 Sep 2005 21:33 GMT
> 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
[quoted text clipped - 7 lines]
>
> Thanks in advance!

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

this.form.elements['e-mail'].value
John - 28 Sep 2005 22:04 GMT
> 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!
web.dev - 28 Sep 2005 22:08 GMT
> > You are accessing the form elements incorrectly.  Try the following
> > instead:
[quoted text clipped - 19 lines]
>
> 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
John - 28 Sep 2005 22:13 GMT
> 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...
web.dev - 28 Sep 2005 22:29 GMT
> > 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
[quoted text clipped - 3 lines]
>
> 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;">
John - 28 Sep 2005 22:38 GMT
> The current action is still submitting the form.  The onClick even
> expects a boolean value to be returned.  To see the expected result you
[quoted text clipped - 3 lines]
> 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.
ASM - 28 Sep 2005 23:44 GMT
John a écrit :

>><input type="submit" value="Go!"
>>onClick="if(this.form.elements['email'].value=='email'){this.form.elements['email'].value='';}
[quoted text clipped - 3 lines]
> 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>

Signature

Stephane Moriaux et son [moins] vieux Mac

John - 30 Sep 2005 21:57 GMT
> <form action="foo.htm"
>  onsubmit="if(this.email.value=='e-mail'){
[quoted text clipped - 6 lines]
> <input type=submit value=GO>
> </form>

Thanks! :-)
Evertjan. - 30 Sep 2005 23:19 GMT
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;"

Signature

Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Lee - 28 Sep 2005 22:43 GMT
web.dev said:

>> > 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
[quoted text clipped - 11 lines]
>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.
John - 28 Sep 2005 23:10 GMT
> 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.
Lee - 28 Sep 2005 23:59 GMT
John said:

>> Better:
>>
[quoted text clipped - 6 lines]
>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.
John - 29 Sep 2005 01:10 GMT
> 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.
Lee - 30 Sep 2005 22:38 GMT
John said:

>> 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.
Mick White - 28 Sep 2005 22:59 GMT
> 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
[quoted text clipped - 5 lines]
>
> 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
John - 28 Sep 2005 23:02 GMT
> 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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.