show/hide some input fields and form validation???

Discussion in 'JavaScript' started by 123GoToAndPlay, Aug 10, 2007.

  1. #1
    So i created a form which has some xtra input fields shown/hidden depending on an user's input.

    But how can i use a correct javascript validation for this form.

    At the moment the validation only works:
    A/ when the extra input fields are hidden (at start)

    Furthermore, i like to validate the xtra input fields if they are shown. If i just validate the inputfield it seems to work, but when i hide the input fields it still want to validate the input fields??

    btw this code i am using for show/hide
    
    function hide(id) {
    	document.getElementById(id).style.visibility = 'hidden';
    	document.getElementById(id).style.display = 'none';
    }
    function show(id) {
    	document.getElementById(id).style.visibility = 'visible';
    	document.getElementById(id).style.display = 'block';
    }
    
    Code (markup):
    Any advice
     
    123GoToAndPlay, Aug 10, 2007 IP
  2. Drag Racer

    Drag Racer Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    just do a simple check to see if the element is visible...

    if (document.getElementById(id).style.visibility == 'visible') {
     do validation...
    }
    Code (markup):
     
    Drag Racer, Aug 10, 2007 IP