Click to See Complete Forum and Search --> : Questions on forms...


brizak79
06-26-2003, 08:48 AM
OK, I've looked all over the JavaScript Source website, and I couldn't find this script...
My bands website has a form for people to sbmit their e*mail address for our mailing list (bottom, left of this page (http://www.sevenmilesun.com/pages/index2.htm)). Real simple: one input box, a submit button, and a reset button. How do I get it so when they click inside the input box, the text dissapears (I have you@email.com as the default value)? Also, is there a way to disable the Submit button if they don't put their email address in there? Hope this made some kind of sense... Thanks!
-Brian

pyro
06-26-2003, 08:55 AM
Something like this should do it:

<script type="text/javascript">
function checkForm(frm) {
if (frm.email.value == "you@email.com" || frm.email.value == "") {
alert ("Please enter your email address.");
return false;
}
return true;
}
</script>


</head>

<body>
<form name="myform" onsubmit="return checkForm(this);">
<input type="text" name="email" value="test" onclick="this.value=''";>
<input type="submit" name="submit" value="Submit">
</form>

brizak79
06-26-2003, 09:02 AM
Thanks!! I'll see if it works tonight...

brizak79
07-11-2003, 01:23 PM
I couldn't get it to work. How would I put it in the following form? Thanks...

<FORM METHOD=post ACTION="http://www.sevenmilesun.com/cgi-bin/sevenmilesun/mail.pl">
<INPUT TYPE=HIDDEN NAME=DESTINATION_ADDR VALUE="mail@sevenmilesun.com">
<INPUT TYPE=HIDDEN NAME=SUBJECT VALUE="Mailing List - Home Page">
<INPUT TYPE=HIDDEN NAME=SUCCESS_HTML VALUE="http://www.sevenmilesun.com/pages/mailinglistthank.htm">
<div align="center">
<PRE><font face="Tahoma" color="#FFCC00" size="1">Sign up for our mailing list:</font>
<font color="#FF0000" face="Tahoma"><INPUT NAME="EMAIL_ADDRESS" SIZE="15" TYPE="text" VALUE="you@email.com"></font></pre>
</div>
<p align="center">
<font color="#FF0000" face="Tahoma">
<INPUT TYPE="submit" VALUE="Join!"><INPUT TYPE="reset" VALUE="Clear"></font></td>
</tr>
</table>
</center>
</div>
</form>

pyro
07-11-2003, 01:27 PM
You might actually be interested in this (http://www.infinitypages.com/research/formvalidation.htm), which will loop through all the form fields and check for empty fields.

brizak79
07-11-2003, 01:35 PM
OK, I got the form to clear when you click in it, but I tried putting that script in the head of the page & in the form, but It won't work. Where does it go? Thanks...

brizak79
07-14-2003, 02:17 PM
Anyone? I'm REALLY new (stupid) at JavaScript...

olerag
07-14-2003, 02:51 PM
Try this where you need it. I do not believe that buttons can
be disabled but I don't believe you need to.

You may also want to include some "email format" validation prior to the submit.

<html>
<head>
<SCRIPT Language=JavaScript>
var eMailDef = "you@email.com";

function resetEMail() {
document.forms[0].eMail.value = eMailDef;
}

function submitEMail() {
var eValue = document.forms[0].eMail.value;

if ((eValue == "") || (eValue == eMailDef)) {
alert("A valid email address must be provided.");
}
else {
alert("Submit the EMail: " + eValue);
}
}
</SCRIPT>
</head>
<body onLoad="resetEMail()">
<center>
EMail Sample
</center>
<p>
<form>
<input type="text" name="eMail" length=50>
<p>
<input type="button" name="Submit" value="Submit" onClick="submitEMail()">
<input type="button" name="Reset" value="Reset" onClick="resetEMail()">
<p>
</form>
</body>
</html>

olerag
07-14-2003, 03:09 PM
Sorry, my reading is a bit lax today. This code will include a default value at the beginning and anytime the reset button is pressed.

Once a legitimate email is accepted, the code changes to the
"receive" value but the actual email value the user includes will
show up in the alert. It is this value you'll pass to your email
processing - whatever that may be.

<html>
<head>
<SCRIPT Language=JavaScript>
var eMailDef = "yourName@email.com";
var eMailRec = "I Have You@email.com";

function resetEMail() {
setEMail(eMailDef);
}

function clearEMail() {
setEMail("");
}

function setEMail(txt) {
document.forms[0].eMail.value = txt;
}

function submitEMail() {
var eValue = document.forms[0].eMail.value;

if ((eValue == "") || (eValue == eMailDef) || eValue == eMailRec) {
alert("A valid email address must be provided.");
}
else {
alert("Submit the EMail: " + eValue);
setEMail(eMailRec);
}
}
</SCRIPT>
</head>
<body onLoad="resetEMail()">
<center>
EMail Sample
</center>
<p>
<form>
<input type="text" name="eMail" size=30 length=50 onFocus="clearEMail()">
<p>
<input type="button" name="Reset" value="Submit" onClick="submitEMail()">
<input type="button" name="Submit" value="Reset" onClick="resetEMail()">
<p>
</form>
</body>
</html>