Handel checkbox's checkd/unckhecked events in javascript
I have a textbox which is read-only. It is used to take input of date from the javascript date picker. Other thing is I have gridview which contains checkbox inside item template. Now what I want is when user clicks on any of the check box in grid, the corresponding date should be filled in the date textbox or when user uncheck that particular check box, texbox should get clear. More over, if the date text box is filled and if he chooses date from date picker, in that case selected date should be filled in date box and selection of checkbox should get clear.. I don't know how to handle开发者_如何转开发 all this things??
<input type="checkbox" id="check_box_id" onclick="doThings(this)" />
<script type="text/javascript">
function doThings(check){
var check= this.checked
if (check==true){
//do stuff when checkbox is checked
}else{
//do stuff when checkbox is unchecked
}
}
</script>
in an GridView there are separate id for each check box and text box. it will like
row1 check box id look like :gridname checkboxname_1 row1 text box id look like :txtname checkboxname_1
row2 check box id look like :gridname checkboxname_2 row2 text box id look like :txtname checkboxname_2
so write a onclick event for checkbox and pass the id and value of check box.
eg: onclick(this.id,checked/Unchecked).
in javascript side get the passed id( gridname checkboxname_1)and take row number using substring method(take the last number 1 or 2 or 3 etc).
then you can get the curresponding textboxt id from that number (if you get 1,just appeng that with txtname checkboxname_).it will give the current text box. so you can use document.getelementbyid(resultantid) to handle the text box when the check box value is chenged.(note that we are also passing check box status.you can use
if(status = checked)
{
getelementbyid(resultantid).clear
}
精彩评论