简体   繁体   中英

using jquery/javascript select box will validate the checkbox

I am getting stuck in a page,where I'm using selectbox & checkbox,and they will behave like - in the select box options are ABC,BCD,BDE,AD,BE & in the checkbox the option are A,B,C,D,E.When I am selecting (suppose) BDE(or AD) from select box....in the checkbox B,D,E(or A and D) will be checked(automatic).

Any idea...or input will be appreciated.

my code(given below):

Edited: one more thing is that if I am using selectbox like(mention below),and want to implemented checked checkbox according to the select box.Any clue...

<body>
<form>
<select name="item" id="item" class="item" onChange=list(this.value) >
<script type="text/javascript">
document.write("<option value=-1>Item</option>");
count=item.length;
for(i=0;i<count;i++)
document.write("<option value="+i+">"+item[i]+"</option>");
</script>
</select>
<table>
<td>
<input type="checkbox" name="A" id="A" value="A" >A<br>
<input type="checkbox" name="B" id="B" value="B">B<br>
<input type="checkbox" name="C" id="C" value="C">C<br>
<input type="checkbox" name="D" id="D" value="D">D<br>
<input type="checkbox" name="E" id="E" value="E">E<br>  
</td>
</table>
</form>
</body>

and on changing that particular select items(item) can all those option can be written in jquery(instead what you have answered) what u have mention(@ mohon ram)

and I have got a link here but not able to sort it on my answer perspective.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script language="javascript">
$(document).ready(function(){

$("select#select_element").change(function(){
    var select_val = $.trim( $("select#select_element option:selected").attr("test") );
    var select_val_arr = select_val.split(",");
    $("input.checkbox").prop("checked",false);
    $.each(select_val_arr, function(i,val){
        $("input:checkbox#"+val).prop("checked",true);
    });
});
$("select#select_element").trigger("change");
});
</script>

</head>
<body>
<select id="select_element">
    <option test="A,B,C" value="ABC">ABC</option>
    <option test="B,C,D" value="BCD">BCD</option>
    <option test="B,D,E" value="BDE">BDE</option>
    <option test="A,D" value="AD">AD</option>
    <option test="B,E" value="BE">BE</option>
</select>

<input type="checkbox" id="A" value="A" class="checkbox" />A
<input type="checkbox" id="B" value="B" class="checkbox"  />B
<input type="checkbox" id="C" value="C" class="checkbox"  />C
<input type="checkbox" id="D" value="D" class="checkbox"  />D
<input type="checkbox" id="E" value="E" class="checkbox"  />E
<input type="checkbox" id="F" value="F" class="checkbox" />F
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM