jwk811 Posted September 25, 2006 Share Posted September 25, 2006 How do you make it so in a form you can "select all" or "unselect all" without having to submit or reload? Please help! Quote Link to comment Share on other sites More sharing options...
extrovertive Posted September 25, 2006 Share Posted September 25, 2006 In the JS src[code]<!-- Beginvar checkflag = "false";function check(field) {if (checkflag == "false") {for (i = 0; i < field.length; i++) {field[i].checked = true;}checkflag = "true";return "Uncheck All"; }else {for (i = 0; i < field.length; i++) {field[i].checked = false; }checkflag = "false";return "Check All"; }}// End -->[/code]In the HTML form:<input type="checkbox" value="Check All" onclick='this.value=check(this.form.yourid)' />Check All <br /><input name="blah" type="checkbox" value="1" id="yourid" /> Quote Link to comment Share on other sites More sharing options...
jwk811 Posted September 25, 2006 Author Share Posted September 25, 2006 Is this script for PHP?[code]<!-- Beginvar checkflag = "false";function check(field) {if (checkflag == "false") {for (i = 0; i < field.length; i++) {field[i].checked = true;}checkflag = "true";return "Uncheck All"; }else {for (i = 0; i < field.length; i++) {field[i].checked = false; }checkflag = "false";return "Check All"; }}// End -->[/code]And this ones for HTML, correct?[code]<input type="checkbox" value="Check All" onclick='this.value=check(this.form.yourid)' />Check All <input name="blah" type="checkbox" value="1" id="yourid" />[/code] Quote Link to comment Share on other sites More sharing options...
yonta Posted September 25, 2006 Share Posted September 25, 2006 That's javascript (the first one) . Put it in the head section between script tags. Quote Link to comment Share on other sites More sharing options...
jwk811 Posted September 25, 2006 Author Share Posted September 25, 2006 Which one should I use? I will try the HTML because I don't know anything about javascript, will that work okay? Quote Link to comment Share on other sites More sharing options...
FrOzeN Posted September 25, 2006 Share Posted September 25, 2006 The html code is what shows the checkbox's on your page. The javascript contains the functions which allows you to create a "Select All" button on your webpage.You would place the javascript code inside <scr[b][/b]ipt type="text/javascript"></script> tags inside your <head></head> tags. Then further down the page in your form you would add the html he posted. Also, with your form make sure it has and [b]id[/b] attribute, and replace "yourid" with the id attribute of your form.If you don't understand what I mean, post your html file and I'll/others here can add it for you. Quote Link to comment Share on other sites More sharing options...
jwk811 Posted September 26, 2006 Author Share Posted September 26, 2006 Okay, so what I'm getting is I add the java script to the head of the html document. Then on the form as an input type I'll add <input type="checkbox" value="Check All" onclick='this.value=check([b]this.form.yourid[/b])' />Check All. And for the bold part I would have to change that correct? Could you give me an example of what I would have to change that to? Do I just list the input names? How would I list them? And am I supposed to name the form too, how would I do that? Quote Link to comment Share on other sites More sharing options...
fenway Posted September 26, 2006 Share Posted September 26, 2006 Not sure why there's a return value to that function call -- you'll have to go through all checkboxes, so an ID is somewhat meaningless. Quote Link to comment Share on other sites More sharing options...
jwk811 Posted September 27, 2006 Author Share Posted September 27, 2006 huh Quote Link to comment Share on other sites More sharing options...
fenway Posted September 27, 2006 Share Posted September 27, 2006 I'm not sure what you're having trouble with at this point. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.