Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with visible/invisible DIVs 1

Status
Not open for further replies.

solfer

Programmer
Jan 17, 2002
7
0
0
GB
I'm using some javascript to validate my form, outputting a standard js alert whenever there's an error.

Instead of a dull old alert, could I make a DIV visible when the script finds an error?

This is my script, with onsubmit="return FormValidator(this)" being called from the Form:


<script Language=&quot;JavaScript&quot;>
function isEmailAddr(submit_by)
{
var result = false
var theStr = new String(submit_by)
var index = theStr.indexOf(&quot;@&quot;);
if (index > 0)
{
var pindex = theStr.indexOf(&quot;.&quot;,index);
if ((pindex > index+1) && (theStr.length > pindex+1))
result = true;
}
return result;
}

function FormValidator(theForm)
{

if (theForm.submit_by.value == &quot;&quot;)
{
alert(&quot;Please enter a value for the \&quot;email\&quot; field.&quot;);
theForm.submit_by.focus();
return (false);
}

if (!isEmailAddr(theForm.submit_by.value))
{
alert(&quot;Please enter a complete email address in the form: yourname@yourdomain.com&quot;);
theForm.submit_by.focus();
return (false);
}

if (theForm.submit_by.value.length < 3)
{
alert(&quot;Please enter at least 3 characters in the \&quot;email\&quot; field.&quot;);
theForm.submit_by.focus();
return (false);
}
return (true);
}
</script>
 
Ya all's you should have to do is put your div out there name and id it then set the style attribute to hidden, then instead of your alert just put in divName.style.visibility=&quot;visible&quot;;

Should do the trick.

Roj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top