Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass checkbox value to javascript function

Tags:

javascript

php

my code is :

<input type="checkbox" name="area" id="area" value="0">Some Text1</input>
<input type="checkbox" name="area" id="area" value="80">Some Text2</input>

and javascript code is

function calc(){var textValue1 = document.getElementById('quantity').value;
var textValue2 = document.getElementById('area').value;
document.getElementById('cost').value = textValue1 * textValue2 ; }

but it isn't working.

like image 474
Niger Sultana Avatar asked Apr 09 '26 22:04

Niger Sultana


1 Answers

Try this:

valueChange = function(item){
	alert(item.value);
}
<form name="form1" method="post" action=" insert_data.php">
    Delivery Location
    <input onChange="valueChange(this)" type="checkbox" name="area" id="area" value="0">Inside city </input>
    <input onChange="valueChange(this)" type="checkbox" name="area" id="area" value="80">Outside city </input>
    </form>
like image 146
kamprasad Avatar answered Apr 12 '26 12:04

kamprasad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!