0
   

What is wrong with my javascript for form onsubmit

 
 
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>
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 856 • Replies: 0
No top replies

 
 

Related Topics

 
  1. Forums
  2. » What is wrong with my javascript for form onsubmit
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 04/26/2024 at 03:36:43