Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 06-23-2008, 03:27 PM Error text
Average Talker

Posts: 20
Trades: 0
I'm trying to get the errortxt <p> tag to show a red error when the user submits but hasn't filled out the required fields. Can anyone help with this?

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="javascript" type="text/javascript">
function CheckTheForm() {
    var result = true;
    var msg="";

if (document.frmTest.name.value=="" OR document.frmTest.eml.value=="") {
     newHTML = "<span style:color = 'red'> Please fill out all required fields.</span>";
document.getElementById('errortxt').innerHTML =newHTML;
        result = false;
}
       
    if (document.frmTest.name.value=="") {
        document.getElementById('title').style.color="red";
        result = false;
       
    }
    if (document.frmTest.eml.value=="") {
            document.getElementById('eml').style.color="red";
            result = false;
            }
   

return result;

}
</script>
</head>

<body>

<form name="frmTest" method="post" action="test_form.html">
<p id="errortxt"></p>
<table width="21%" border="0">
  <tr>
    <td id="title">Name</td>
    <td><input type="text" name="name" /></td>
  </tr>
  <tr>
    <td id="eml">email</td>
    <td><input type="text" name="eml" /></td>
  </tr>
  <tr>
    <td><input type="submit" name="Submit" value="Submit" onclick="return CheckTheForm();" /></td>
    <td><input type="reset" name="Reset" value="Reset" /></td>
  </tr>
</table>
</form>
</body>
__________________
Website:

Please login or register to view this content. Registration is FREE
ffsja is offline
Reply With Quote
View Public Profile Visit ffsja's homepage!
 
 
Register now for full access!
Old 06-23-2008, 05:26 PM Re: Error text
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
Change this:
Code:
<span style:color = 'red'>
to this:
Code:
<span style=\"color:red\">
__________________
~nyef

Please login or register to view this content. Registration is FREE
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-23-2008, 07:43 PM Re: Error text
Average Talker

Posts: 20
Trades: 0
Thank you. I made that change but it still submits the form if the user doesn't fill out the fields. It should prevent them submitting the form if the fields aren't filled out AND print the red text at the top. Right now it does neither as far as I can tell (it submits before I can check if it prints red text).

It doesn't submit if I take this code out:

Code:
if (document.frmTest.name.value=="" OR document.frmTest.eml.value=="") {
     newHTML = "<span style:color = 'red'> Please fill out all required fields.</span>";
document.getElementById('errortxt').innerHTML =newHTML;
        result = false;
}
So I know part of the problem at least is contained in that code. Any other ideas out there?
__________________
Website:

Please login or register to view this content. Registration is FREE
ffsja is offline
Reply With Quote
View Public Profile Visit ffsja's homepage!
 
Old 06-24-2008, 02:23 AM Re: Error text
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
change "OR" to ||
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 06-25-2008, 12:27 PM Re: Error text
Average Talker

Posts: 20
Trades: 0
Thanks willcode4beer! I owe you one
__________________
Website:

Please login or register to view this content. Registration is FREE
ffsja is offline
Reply With Quote
View Public Profile Visit ffsja's homepage!
 
Reply     « Reply to Error text
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21181 seconds with 12 queries