SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Pedantic Semantic blain's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Noob validation questions

    It's probably a very simple answer.

    I have some client side validation on a form, one line of this is


    Code JavaScript:
    if (document.getElementById("card_type").value == "") errors+='- card type\n';

    This checks if the field is empty.

    I would like to validate the folowing rule too, but I cannot get my head around the syntax.

    if card_type is "SWITCH" and issue is "" errors+='- issue\n';
    Technology is dominated by two types of people:
    those who understand what they do not manage,
    and those who manage what they do not understand.

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2006
    Location
    Newcastle, England
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you do the following:

    Code JavaScript:
    var errors = null;
     
    if (document.getElementById("card_type").value == "") 
    {
    	errors += '- card type missing\n';
    }
     
    if ((document.getElementById("card_type").value == "SWITCH") AND !errors)
    {
    	// passed validation
    	return
    }
    else
    {
    	errors += '- card type invalid\n';
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •