lalabored Posted June 18, 2007 Share Posted June 18, 2007 When I use this code, it works fine... var 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"; } } However, when I use this... var checkflag = "false"; function checkAll(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"; } } It doesn't work. Is there something about Javascript that does this? Quote Link to comment Share on other sites More sharing options...
nogray Posted June 18, 2007 Share Posted June 18, 2007 make sure you call the right function check or checkAll Quote Link to comment Share on other sites More sharing options...
lalabored Posted June 18, 2007 Author Share Posted June 18, 2007 make sure you call the right function check or checkAll Yes, I checked that, this is what I used. This works... <script type="text/javascript"> var 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"; } } </script> <input type="button" onclick="this.value = check(document.getElementsByName('pm[]'));" value="Check All"> This doesn't work... <script type="text/javascript"> var checkflag = "false"; function checkAll(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"; } } </script> <input type="button" onclick="this.value = checkAll(document.getElementsByName('pm[]'));" value="Check All"> I don't see any difference yet it doesn't work, I don't understand why... I'm using Firefox if that helps. Quote Link to comment Share on other sites More sharing options...
nogray Posted June 19, 2007 Share Posted June 19, 2007 both these scripts work fine, make sure you don't have an error somewhere else in your code that stops the script from working. In firefox, after you get the error click on "Tools" from the top menu (next to File, Edit, View) and select "Error Console" (or Javascript Console if you have an older version). This should let you know where is your error. Quote Link to comment Share on other sites More sharing options...
lalabored Posted June 24, 2007 Author Share Posted June 24, 2007 Oh, okay, thanks. 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.