PDA

View Full Version : save undefined value from checkbox



newphpbees
11 Apr 2012, 11:37 PM
Hi..

I have checkbox and I need to get his value.

I create function for checkbox if checkbox is clicked it is true then the checkbox value is H else W.



function chk(){

if(document.getElementById('H').checked==true){
var H = document.getElementById('H'). value = H;
}

else if(document.getElementById('H').checked==false){
var H = document.getElementById('H'). value = W;
}

}


and I have function for save :



function ApproveLeaveOP(){
var H = document.getElementById('H').value;
document.sampleform.action="AddLeave.php?H="+H;
document.sampleform.submit();

}
<input type="checkbox" name="H" id="H" value="" onclick="chk()">


I don't know how can I add value to the checkbox if I click the value will be H if not the value is W.

I am new in using checkbox.
Thank you so much..

Kirsteins
13 Apr 2012, 01:49 AM
In function chk() you are assigning non-literal values (H and W) to the variable H. Are H and W defined somewhere?