lundi 15 août 2016

check if selected option and checkbox is checked

I have some problems here with javascript. I want someone to choose an option and a checked box, and if both are checked then other checkboxes should not be able to click. I had tried to give the function 2 parameters (one is for the option and one for the checkbox).

function bs(id /*,chbxvalue */ ){
var selectElement = document.getElementById(id);
var selectValue = selectElement.options[selectElement.selectedIndex.]value;

//var select2Element = document.getElementById(chbxvalue);
//var selectCHBXval = select2Element.options[select2Element].selectedIndex.]value;

if(selectValue == "banana" /*&& document.getElementById("apple").checked == true */)
   {
    document.getElementById("juice").checked = true;
   }
else if(selectValue =="Salad")
   {
   }
}

The thing in the comments doesn't work. :/

<div id="flavor"><br />
  <select id="bss" name="beh" onChange="bs('bss')">
     <option value="banana" >banana</option>
     <option value="pinnaple" >pinnaple</option>
  </select>
</div>

<div id="divcontainer" class="cont" style="display:block;">
       <input type="checkbox" name="deckel" id="apple" value="dstSD1" />Apples <br />
       <input type="checkbox" name="juices" id="juice" value="d2" />Fruitjuice <br />
</div>

I've changed the names here. Has anybody an idea? Sorry, Iam not so good with javascript. Its like about a method of elimination for things (if a and b is used, cancel c. Else if a and d is used check g and cancel o.)




Aucun commentaire:

Enregistrer un commentaire