PDA

View Full Version : document.write


mw2005
08-25-2005, 07:10 PM
Hi all;
I have a form and it checks to see if both email enteries are correct. I used document.write to display if the emails are not the same but it opens in a different page. If there is an error how can i display it next to the email fields.

Any help will be appreciated,
Thanks in Advance,
MW2005

<script Language="JavaScript">
<!--
function Validate(contactform)
{

// check if both password fields are the same
if (contactform.mail.value != contactform.verifymail.value)
{
document.write("The two emails are not the same.");
contactform.verifymail.focus();
return (false);
}

return (true);
}

//-->
</script>

<form action="" method="POST" onsubmit="return Validate(this)" name="Form">


email:
<input type="text" size="10" name="mail">

Verify email:
<input type="text" size="10" name="verifymail"><br><p>


<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset"><p>
</form>

Brandoe85
08-25-2005, 08:49 PM
document.write() will write over the current document, use innerHTML (http://www.w3schools.com/dhtml/dhtml_dom.asp)

Good luck

mw2005
08-28-2005, 09:44 AM
I have followed the link but i still can not make it work. Can you show me how to do it?

Thanks in Advance,
MW2005

vwphillips
08-28-2005, 10:18 AM
<script Language="JavaScript">
<!--
function Validate(contactform)
{

// check if both password fields are the same
if (contactform.mail.value != contactform.verifymail.value)
{
alert("The two emails are not the same.");
contactform.verifymail.focus();
return (false);
}

return (true);
}

//-->
</script>

mw2005
08-28-2005, 05:53 PM
Hi all;
I have a form and it checks to see if both email enteries are correct. I used document.write to display if the emails are not the same but it opens in a different page. If there is an error how can i display it next to the email fields.


Please can anybody help me,
Thanks in Advance,
MW2005

(Can you show me how to do it using inner.html instead of document.write)

_Aerospace_Eng_
08-28-2005, 06:52 PM
I don't think you have even tried. You can't always expect things to be handed down to you.
<script type="text/javascript">
<!--
function Validate(contactform)
{

// check if both password fields are the same
if (contactform.mail.value != contactform.verifymail.value)
{
document.getElementById('same').innerHTML='The two emails are not the same.';
contactform.verifymail.focus();
return (false);
}

return (true);
}

//-->
</script>
Place the below where you would like the words to appear.
<span id="same"></span>

mw2005
08-28-2005, 06:56 PM
Thanks for that, i forgot to put in the <span id="same"></span>