Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2010
    Thanked 0 Times in 0 Posts

    Form instant validation - validate field value based on other field value

    I am using javascript to instantly validate as a user types into a form. Livevalidation is where I got the snippet. I like, it, but it doesn't allow to validate one field value based in another value in the form.

    So I tried to alter the code and it works great in Mozilla but not in IE. That probably means I'm doing something wrong. I'm not really familar with Javascript.

    My situation. If a user picks "Other" in drop down, then he/she needs to specify in the next field why they picked "Other"; So with my instant validation, I want it to generate an error when the user tries to leave the second field (Other) blank.

    My form with two fields and Javascript:

    <form action="ex.php" method="post">
    <legend><span>Contract Details</span></legend>
    <label for="contractType">Type Of Contract</label>
    <select name="contractType" id="contractType">
            <option>Contract 1</option>
            <option>Contract 2</option>
    <label  for="contractTypeOther">If you picked "Other", specify</label>
    <input id="contractTypeOther" name="contractTypeOther" class="text" type="text" maxlength="100" />
    <script type="text/javascript">
    var contractTypeOther = new LiveValidation('contractTypeOther');
    contractTypeOther.add( Validate.Custom3, { match: 'contractType' } );
    <fieldset class="submit">
    <input class="submit" type="submit" value="Submit" />
    The code that is being fetched (in my JS file):

    Custom3: function(value, paramsObj){
          	var paramsObj = paramsObj || {};
        	var message = paramsObj.failureMessage || "You picked \"Other\". Please specify!";
        	var match = paramsObj.match.nodeName ? paramsObj.match : document.getElementById(paramsObj.match);
        	if(match.value =='Other' && value==''){
        	return true;
    It does work in Firefox, not in IE. Please help me catch the bad guy!

  2. #2
    New to the CF scene
    Join Date
    Jul 2013
    Thanked 0 Times in 0 Posts
    I know this was posted a few years ago but I'm trying to do the same thing, validate a field based off of another using LiveValidation. I want to use your code but like you said, it doesn't work in IE. Did you find a solution to this?

  3. #3
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Thanked 1,008 Times in 1,005 Posts
    Since you did not post your code I'll use the first example.
    I'd a made the "Why did you choose other" input box invisible and only made it visible if OTHER were chosen.
    In the javascript I would have used an if statement to evaluate that box if the value of 'contractType' was other.

    Please note the above code for the select is not coded correctly, look it up.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.


Tags for this Thread

Posting Permissions

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