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 05-26-2009, 12:35 PM validation.js
Experienced Talker

Posts: 37
Name: Ryan
Location: Indianapolis, IN
Trades: 0
I am working on the validation for a form. I have a couple places where I am confused. What do you put for checkboxes, radio buttons, and select dropdowns? Thanks.

*edit* and text areas for that matter.

Validation.js

Code:
<script type="text/javascript">
    function validate_required(field,alerttxt)
    {
    with (field)
      {
      if (value==null||value=="")
        {
        alert(alerttxt);return false;
        }
      else
        {
        return true;
        }
      }
    }
    
    function validate_email(field,alerttxt)
    {
    with (field)
      {
      apos=value.indexOf("@");
      dotpos=value.lastIndexOf(".");
      if (apos<1||dotpos-apos<2)
        {alert(alerttxt);return false;}
      else {return true;}
      }
    }

    function validate_form(thisform)
    {
    with (thisform)
      {
      if (validate_required(interview,"Please enter the name of your interviewer.")==false)
          {interview.focus();return false;}
    
      if (validate_required(name,"Please enter your name.")==false)
             {name.focus();return false;}
            
      if (validate_required(email,"Please enter email address.")==false)
            {email.focus();return false;}
    
      if (validate_email(email,"The email address entered is not valid.")==false)
         {email.focus();return false;}
     
      if (validate_required(age,"Please select an age.")==false)
             {age.focus();return false;}
      

      
      }
    }


</script>

Last edited by indyryan; 05-26-2009 at 12:37 PM..
indyryan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-31-2009, 11:41 AM Re: validation.js
Physicsguy's Avatar
404 - Title not found

Latest Blog Post:
Challenges
Posts: 824
Name: Scott
Location: Ontario
Trades: 0
You could put; and I'm a Javan00b, but I think this is what you mean:

It's not in Javascript ^^^^^^^

if checkbox = empty execute this function

if checkbox = filled execute this function

Here's my atepmt with the actual javascript:

Code:
<script type="text/javascript">

function displaymessage()
{
document.write("You just checked the checkbox!");
}

</script>
<form>
<input type="checkbox" onclick="document.write(displaymessage())" />
</form>
That script displays a message saying 'you just checked the checkbox!' when you click it.

Right now your code does nothing, it doesn't output anything, I mean. You need to give things name to correspond to the fiends.

Oh, and you don't want textareas, you want inputs.

Here's a simple input box that goes with a script.

Code:
<input type="text" id="myinputfield" />
__________________
Check out my
Please login or register to view this content. Registration is FREE

Last edited by Physicsguy; 05-31-2009 at 11:47 AM..
Physicsguy is online now
Reply With Quote
View Public Profile
 
Old 05-31-2009, 01:36 PM Re: validation.js
Decaf's Avatar
Ultra Talker

Posts: 489
Name: Adam
Trades: 0
You don't need / can't have the "<script type='...'>" tags in a .js file.
__________________

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

Decaf is offline
Reply With Quote
View Public Profile Visit Decaf's homepage!
 
Old 05-31-2009, 01:54 PM Re: validation.js
Physicsguy's Avatar
404 - Title not found

Latest Blog Post:
Challenges
Posts: 824
Name: Scott
Location: Ontario
Trades: 0
ooh yeah

Sorry
__________________
Check out my
Please login or register to view this content. Registration is FREE
Physicsguy is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to validation.js
 

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.16555 seconds with 12 queries