Reply
Tue 15 Jul, 2014 08:03 am
please lookinto my code the onsubmit is not working
the function getSelectedChbox(frm) will collect checkboxes values
<?php echo var_dump(isset($_POST['values']) ? $_POST['values'] : 'Submit first.'); ?>
<form action="script.php" method="post" onsubmit="return getcheks()">
<input type="checkbox" name="chb1" value="html" />HTML<br/>
<input type="checkbox" name="chb2" value="css" />CSS<br/>
<input type="checkbox" name="chb3" value="javascript" />JavaScript<br/>
<input type="checkbox" name="chb4" value="php" />php<br/>
<input type="checkbox" name="chb5" value="python" />Python<br/>
<input type="checkbox" name="chb6" value="net" />Net<br/>
<input type="hidden" name="values" id="values" value="" />
<input type="submit" value="Click" id="btntest" />
</form>
<script type="text/javascript"><!--
function getSelectedChbox(frm) {
var selchbox = [];
var inpfields = frm.getElementsByTagName('input');
var nr_inpfields = inpfields.length;
for(var i=0; i<nr_inpfields; i++) {
if(inpfields.type == 'checkbox' && inpfields.checked == true)
selchbox.push(inpfields.value);
}
return selchbox;
}
function getcheks(){
var selchb = getSelectedChbox(this.form);
var values = selchb.join(', ');
document.getElementById('values').value = values;
return true;
}
//-->
</script>