/    Sign up×
Community /Pin to ProfileBookmark

hi
i am having a JS code for validation some checkboxes like this….
——————————CODE—————————————

function val() // Function to call checkbox function (?)
{

if (!is_multiple_checked())
{
alert (‘Please Select Something’);
return false;
}

return true;
}

function is_multiple_checked() // Function to check that one or more radio buttons are selected
{

var formObj = document[‘form1’][‘sub[]’];
var count = 0;
for (i=0;i<formObj.length; i++)
{
if(formObj[i].type == ‘checkbox’)
if(formObj[i].checked)
count++;
}
if (count < 1)
return false;
else if(count >=1)
return true;

}


————————————————————————–

it is working fine for more than one checkbox ie when there are more than 1 checkbox and if i dont select anyone of them then it prints the alert msg. ; the problem is when there is only one checkbox and when i check it press the Submit button then also it is giving me the alert msg.

What can be the fault????
i am giving the code for checkboxes also(its the same one excepy it takes values from a file)

————————–CHECKBOX CODE——————————–

<?php
for($j=0;$j<$length-1;$j++)
{

$sub = $data[$j];
$subname = $mainh.$j; /////sub is the value i am taking 4m a file
?>
<input type=checkbox name=”sub[]” value=”<?php echo “$sub”; ?>” >
<?php echo “$sub”; ?><br>

<?php
} /////////////////////////////////////////// for ends
?>


————————————————————————–

ie when the value taken from file 4 “$sub” is one ,only one checkbox appears on the page and then that validation is giving me problem !!!!!!!!!!

can u do something???? u can take some values for “$sub” instead taking them from a file
-thanks
-ashish

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@bokehJan 28.2006 — Please post in the correct forum. This is the PHP forum; you need the javascript forum.
×

Success!

Help @ashishrathore spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...