jquery - Add value in span using JavaScript -
i want add 500 using onclick function in span 1000 means onclick @ check box sapn value 1500
js
function add() { if (document.form1.checkbox1.checked == true) { // code here sum 500 in 1000 } }
html
<form name="form1" style="color: green ; font-size: 150%" action="#"> <input type="checkbox" name="checkbox1" onclick="add()" />500 <br /> <span>1000 </span> </form> </body>
if don't want use jquery, the following can used.
function add(element) { var form = document.getelementsbyname("form1")[0]; var val = form.getelementsbytagname('span')[0].innerhtml; if (element.checked == true) { form.getelementsbytagname('span')[0].innerhtml = parseint(val) + parseint(element.value); } else { form.getelementsbytagname('span')[0].innerhtml = parseint(val) - parseint(element.value); } }
<form name="form1" style="color: green ; font-size: 150%" action="#"> <input type="checkbox" name="checkbox1" onclick="add(this)" value="500" />500 <br /> <span>1000</span> </form>
Comments
Post a Comment