/    Sign up×
Community /Pin to ProfileBookmark

Auto click checkbox help

I am do the auto click checkbox on the image. When user click on the image, the checkbox while be autoclick by one, and the second time click, second checkbox will be auto click and etc.

[CODE]
var ini=1;
function check()
{
ini++;
var i=1, c;
while(c=document.getElementsByName(‘checkbox[]’)){
i<=ini?c.checked=true:null;
}
<div>
<img src=”sun2_.jpg” onClick=”check();”/>
</div>

<?php
for($j=1; $j<24; $j++){
for($i=1; $i<13; $i++){
?>

<input type=”checkbox” name=”checkbox[]”/>
<?php
}
}
?>
[/CODE]

Can anyone guide me to the right way? Because the JavaScript code not running as i expected i.e when i click on the image, nothing happened.

Any help would appreciate.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@criterion9Mar 23.2009 — I don't know if this is your whole problem but you have a syntax error in your check function.
<i>
</i>function check() <br/>
{ <br/>
ini++;
var i=1, c;
while(c=document.getElementsByName('checkbox[]')){
i&lt;=ini?c.checked=true:null;
}

You are missing the second "}" since you open one for the function and a second one for the while statement.
Copy linkTweet thisAlerts:
@wterauthorMar 23.2009 — Thanks for reply. I already add the '{' to the function check. But the problem still no solved. Criterion9, you have any idea to fixed this?
Copy linkTweet thisAlerts:
@criterion9Mar 24.2009 — Are you getting any javascript errors from firefox error console or firebug? If so please post those here. Also you can check the outputted source to make sure it is coming out the way you are expecting.
Copy linkTweet thisAlerts:
@wterauthorMar 24.2009 — No javascript error from firefox. What i want is when user click on image, the checkbox can be tick on it automatically where the image position that the user clicked. I already tried to debug the code but do not know what is missing to get the expected output.
Copy linkTweet thisAlerts:
@criterion9Mar 24.2009 — What do you mean by:

What i want is when user click on image, the checkbox can be tick on it automatically where the image position that the user clicked.
[/quote]


Do you want a checkbox next to an image to be checked when you click that image? Do you want all checkboxes to be checked one at a time when you click a single image?

You really didn't make much sense in the post above. A little clarification would be needed before anyone will be able to help you.
×

Success!

Help @wter 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.19,
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,
)...