/    Sign up×
Community /Pin to ProfileBookmark

Urgent help plzzzzzzzzzz

HI guys I’m facing problem with check boxes again.. ?
I want to alert if there are no check boxes clicked and then focus back on check boxes..My code given below works fine if I have more then 1 check box but if I have one it gives error…can anyone help

flag = 0;
for(i=0;i<document.ven.camera.length;i++)
{
if(document.ven.camera[i].checked == true)
{
flag = 1;
}
}
if(flag == 0)
{
alert(‘Please choose Camera’);
document.ven.camera[0].focus();
return;
}

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Brandoe85Nov 18.2004 — I actually saw something exactly like this resolved [URL=http://www.codingforums.com/showthread.php?t=46121&page=2&highlight=checkboxes]here[/URL]
Copy linkTweet thisAlerts:
@ysheraziauthorNov 18.2004 — nope its still ain't working for me.if I have one checkbox and I click on it still it's alerting that check box not clicked.
Copy linkTweet thisAlerts:
@Brandoe85Nov 18.2004 — Hmm..when I copy that exact code and test it, it's working for me, with 1 checkbox or more than 1.
[CODE]
<html>
<head>
<script type="text/javascript">
var txt = window.navigator.appName;
var ie = (txt == "Microsoft Internet Explorer") ? true : false;
var opera = (txt == "Opera") ? true : false;
</script>
<script type="text/javascript">
function validate()
{
var list = (ie) ? document.getElementById('formu').getElementsByTagName('input') : document.getElementsByName('blah');
for(var m = 0; m < list.length; m++)
{
if (ie && list[m].getAttribute('name') != 'blah')
{
continue;
}
if(list[m].checked == true)
{
return true;
}
}
alert("Debe seleccionar al menos un anuncio para borrar" + m);
return false;
}
</script>
</head>
<body>
<form name="formu">
<input type="checkbox" name="blah">
<input type="checkbox" name="blah">
<input type="button" name="send" value="Check" onclick="validate();">
</form>
</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@ysheraziauthorNov 18.2004 — thanx man I just used an extra condition because for one checkbox length was undefined so I used if condition for that and then tackled one checkbox it it's checked or not...

anyway thanx alot

regards

Yasir
×

Success!

Help @ysherazi 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...