Delete drop down when it is blank using Javascript or Jquery -


is possible write javascript function delete drop down when blank?

<form name="myform" method="post" enctype="multipart/form-data" action="" id="myform"> <div> <label id="question1">1) draw recognizable shapes</label>         <br /> <input type="radio" value="yes" id="question1_0" name="question1_0" />         yes <input type="radio" value="no" id="question1_1" name="question1_1" />         no </div> <div> <label id="question2">2) competently cut paper </label>         <br /> <input type="radio" value="yes" id="question2_0" name="question2_0" />         yes <input type="radio" value="no" id="question2_1" name="question2_1" />         no </div> <div> <label id="question3">3) hold pencil</label>         <br /> <input type="radio" value="yes" id="question3_0" name="question3_0" />         yes <input type="radio" value="no" id="question3_1" name="question3_1" />         no </div> <input type="submit" value="delete drop down" onclick="return checkanddelete"/> </form> 

if not select question 2 example, deletes question 2 label , drop down.

assuming meant radio button groups (and not drop down lists) firstly html incorrect, need set name values of each group of radio buttons same:

<input type="radio" value="yes" id="question1_0" name="question1" /> yes <input type="radio" value="no" id="question1_1" name="question1" /> no 

then need loop through list of radio buttons, if none in group selected delete parent div:

$('input[type=submit]').on('click', function() {     var radioarr = [];     $(':radio').each(function(){         var radname = this.name;         if($.inarray(radname, radioarr) < 0 && $(':radio[name='+radname+']:checked').length == 0)         {             radioarr.push(radname);             $(this).closest("div")                    .remove();         }     });     return false; //to stop form submitting testing purposes }); 

while there, might want add <label for=""> tags around text.

here jsfiddle of solution.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -