emptying a field

B

barney

I'm wondering if I can use JS to forcibly empty a form field (sorry if
this is an FAQ - I can't find much reference to it in the group via a
quick Google search, and the one solution I did locate doesn't seem to
work).

The relevant bits of the form and script are below. The alert when the
contents of the two fields don't match DOES work, as does the focus on
the field NewPassword, but I would like if possible to empty the fields
NewPassword and NewPasswordAgain when they don't match.

<SCRIPT language="JavaScript" type="text/javascript">
<!--
function checkData()
{
var f = document.forms["new_entry"]

if(!(f.NewPassword.value == f.NewPasswordAgain.value))
{
alert("The two entries of your password didn't match.");
f.NewPassword.value == ''";
f.NewPasswordAgain.value == "'';
f.NewPassword.focus();
return false;
}


return true;
}
//-->


<FORM name="new_entry" method="GET" action="submit_company.asp"
target="_self" onSubmit="return checkData();">
<P>Choose a password of five to ten characters.</P>
<INPUT type="text" size="10" maxlength="10" class="visibletextinput"
name="NewPassword">
<BR>
<P>Re-enter password:</P>
<INPUT type="text" size="10" maxlength="10" class="visibletextinput"
name="NewPasswordAgain">
<BR><BR>
<INPUT type="submit" class="submitsmall" value="continue">
</FORM>
 
B

barney

Dohhhhhhhhhhhhhh! It works just fine - I was uploading the new version
of the file into the wrong FTP directory!!! Sorry about that. ;)
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Sun, 9 Apr 2006 09:21:54 remote, seen in
I'm wondering if I can use JS to forcibly empty a form field (sorry if
this is an FAQ - I can't find much reference to it in the group via a
quick Google search, and the one solution I did locate doesn't seem to
work).

The relevant bits of the form and script are below. The alert when the
contents of the two fields don't match DOES work, as does the focus on
the field NewPassword, but I would like if possible to empty the fields
NewPassword and NewPasswordAgain when they don't match.

<SCRIPT language="JavaScript" type="text/javascript"> ^^^^^^^^^^^^^^^^^^^^^
Superfluous.

<!--

Not required in browsers; though could be helpful with other software.

if(!(f.NewPassword.value == f.NewPasswordAgain.value))
if( f.NewPassword.value != f.NewPasswordAgain.value )
f.NewPassword.value == ''";
^^ ^^^

Looks wrong, twice. Copy'n'paste code for safety, don't re-type/

<P>Choose a password of five to ten characters.</P>
<INPUT type="text" size="10" maxlength="10" class="visibletextinput"
xxxx
should be password : you have more " than are necessary.
 
T

Thomas 'PointedEars' Lahn

Dr said:
[...] (e-mail address removed) posted :

Not required in browsers; though could be helpful with other software.

That is an understatement: the line makes use of a proprietary extension
of ECMAScript in an HTML context. In a strict ECMAScript implementation,
it would be syntactically incorrect (`<', `!', and `--' being operators)
and therefore trigger a syntax error.

In an XHTML context that is parsed by an XML parser, it is likely to
comment out the entire script, so that the script engine will never see it.


PointedEars
 
B

barney

Thanks, John. Not sure how the superfluous quotes happened - they're
not in my text file!

wrt the INPUT type, I thought about password, but figured that - since
the possible user error here is not typing the same password twice - it
would be more useful for them if the characters were visible.
 

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top