Hi all,
I have a programme where I have 50 questions . I have written js functions to validate each.
but now problem is at form I cant't call every methode.
so I have to put all code into one methode and check.
Is it ok? are there any alternative option?
thx in advanc....
4 Replies - 303 Views - Last Post: 20 January 2012 - 10:56 AM
Topic Sponsor:
#1
calling several javascript functions at the form submit
Posted 20 January 2012 - 09:19 AM
Replies To: calling several javascript functions at the form submit
#2
Re: calling several javascript functions at the form submit
Posted 20 January 2012 - 10:34 AM
hi here is the code
Problem is alway alert the "Question 1 is not completed ! " thought I checked a radio button from group 1. how to correct this?
thx inadvance...
<script type="text/javascript">
function validat_UserInputs()
{
return checkRadioQ1();
return checkRadioQ2();
return true;
}
function checkRadioQ1()
{
var radios = document['form1'].elements['gender'];
for (var i=0; i <radios.length; i++) {
if (radios[i].checked) {
}else
{
alert("Question 1 is not completed ! ");
return false;
}
}
}
function checkRadioQ2()
{
var radios2 = document['form1'].elements['ace'];
for (var i=0; i <radios2.length; i++) {
if (radios2[i].checked) {
}
else
{
alert("Question 2 is not completed ! ");
return false;
}
}
}
Problem is alway alert the "Question 1 is not completed ! " thought I checked a radio button from group 1. how to correct this?
thx inadvance...
#3
Re: calling several javascript functions at the form submit
Posted 20 January 2012 - 10:45 AM
checkRadioQ1() checks if every radio button with the name gender is checked, which is impossible (you can only check one radio button of a group with the same name).
if your browser supports CSS3’s pseudo-class :checked and all the buttons have an exclusive class name you coud use
even some scope magic is possible
if your browser supports CSS3’s pseudo-class :checked and all the buttons have an exclusive class name you coud use
if (0 === document.querySelectorAll(".gender:checked").length) {
// radio button group is unchecked
}
even some scope magic is possible
var gender = document.form1.gender;
var checked = [].filter.call(gender, function(item) {
return item.checked;
});
if (0 === checked.length) {
// radio button group is unchecked
}
This post has been edited by Dormilich: 20 January 2012 - 10:58 AM
#4
Re: calling several javascript functions at the form submit
Posted 20 January 2012 - 10:48 AM
<?php $attri=array('name'=>"form1",'onsubmit'=>"return validat_UserInputs()");
echo form_open('welcome/saveData',$attri); ?>
<ol type="1" style="margin: 35px;">
<li>
<label>Gender</label><br>
<label>Male </label> <input type="radio" name="gender" value="M" />
<label>Female </label><input type="radio" name="gender" value="F" />
</li>
<br>
<br>
<li><label>Race</label><br>
Sinhalese <input type="radio" name="ace" value="sinhalese" />
Tamil <input type="radio" name="ace" value="tamil" />
Muslim <input type="radio" name="ace" value="muslim" />
Burgher <input type="radio" name="ace" value="burger" />
Malay <input type="radio" name="ace" value="malay" />
Other <input type="radio" name="ace" value="other" />
</li><br><br>
</form>
thx,
#5
Re: calling several javascript functions at the form submit
Posted 20 January 2012 - 10:56 AM
see previous post.
additionally, <br> is no allowed inside <ul> and <ol>. use padding or margin to fix the distance.
additionally, <br> is no allowed inside <ul> and <ol>. use padding or margin to fix the distance.
This post has been edited by Dormilich: 20 January 2012 - 11:01 AM
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote



|