html - Javascript Radio Buttons Functionality bug -
i'm try couple things radio buttons form, , i'm having lot trouble. there 2 radio buttons right now, work together. want have 3 scenarios form.
- neither of radio buttons checked, hide or disable 2 other elements. (text box , dropdown list)
- the first radio button checked, hide or disable 1 element.
- the second radio button checked, hide or disable 1 element.
in 3 scenarios need form return values user, whether nothing, or radio button check , element available radio button. please keep in mind form contain other radio buttons later on separate these. mention want keep in plain javascript if possible.
currently i'm trying use .disable , .checked, not luck. please me figure out. please include explanation of answer if possible can understand it.
here forms code :
<input type="radio" name="clubmember" id="member" value="member" />club member <input type="radio" name="clubmember" id="nonmember"value="nonmember" />non member <br /> <br /> select club. <select name="clublist"> <option value="cluba">club a</option> <option value="clubb">club h</option> </select><br /> <!-- or --> club, or guest? <br /> <textarea rows="5" cols="25" name="nonclubinfo">briefly explain here </textarea> <button type="submit" onclick="return validateregistrationform()" >register</button>
here code script :
function validateclubinfo() { if(document.getelementbyid("member").checked == false && document.getelementbyid("nonmember").checked == false) { document.getelementbyid("clublist").disabled = true; document.getelementbyid("nonclubinfo").disabled = true; alert("this test"); return true; } else if(document.getelementbyid("member").checked == true) { document.getelementbyid("nonclubinfo").disabled = true; return true } else if(document.getelementbyid("nonmember").checked == true) { document.getelementbyid("clublist").disabled = true; return true; } }
i should note validation gets checked through second function, left out because long function , has nothing problem.
at rate on matter appreciated.
it looks problem you're using document.getelementbyid find select/textarea, haven't assigned ids elements. try adding id this:
<select name="clublist" id="clublist> <option value="cluba">club a</option> <option value="clubb">club h</option> </select><br />
Comments
Post a Comment