wtf loop!??! v. javascript

Discussion in 'OT Technology' started by elevator, Apr 8, 2010.

  1. elevator

    elevator The tenants think it's wonderful! ヽ(´ OT Supporter

    Joined:
    Mar 25, 2005
    Messages:
    10,967
    Likes Received:
    0
    Location:
    Houston, TX
    you work correctly when a radio button is not selected, but you have other if statements below you! why don't you go to the next if statement after you make sure at least one of the radio buttons are selected? You automatically return true without even letting the next if statement tell me I don't have anything in the last name field BUT if I take you out, all works well (except of course your validation) :madfawk:

    Code:
    if (document.register.name1.value.length > 0) {
    	var radio_choice = false;
    	if (document.register.membership1[0].checked || document.register.membership1[1].checked) {
    		radio_choice = true;
    	}
    	if (radio_choice == false) {
    			alert("For Forum Registrant #1 (" + document.register.name1.value + "), you must select Member or Non-Member");
    			return false;
    	}
    }
    

    whole function
    Code:
    function validate() {
    
    
    if (document.register.name1.value.length > 0) {
    	var radio_choice = false;
    	if (document.register.membership1[0].checked || document.register.membership1[1].checked) {
    		radio_choice = true;*
    	}
    	if (radio_choice == false) {
    			alert("For Forum Registrant #1 (" + document.register.name1.value + "), you must select Member or Non-Member");
    			return false;
    	}
    }
    
    
    
    
    if (document.register.lastname.value == "") {
    alert("Please enter your last name");
    return false;
    }
    
    if (document.register.firstname.value == "") {
    alert("Please enter your first name");
    return false;
    }
    
    return true;
    
    }
    
     
  2. elevator

    elevator The tenants think it's wonderful! ヽ(´ OT Supporter

    Joined:
    Mar 25, 2005
    Messages:
    10,967
    Likes Received:
    0
    Location:
    Houston, TX
    oh, I found it. Ran it in safari's debugger and once it set the radio_choice variable to true, it skipped to the return true at the bottom of the function... It also showed a weird character after radio_choice = true;

    That * showed up as a space on notepad and when i deleted the "space," it continued onto the next if statement
     

Share This Page