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? Link to comment https://forums.phpfreaks.com/topic/56001-solved-why-does-this-happen/ 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 Link to comment https://forums.phpfreaks.com/topic/56001-solved-why-does-this-happen/#findComment-276914 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. Link to comment https://forums.phpfreaks.com/topic/56001-solved-why-does-this-happen/#findComment-277204 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. Link to comment https://forums.phpfreaks.com/topic/56001-solved-why-does-this-happen/#findComment-277767 Share on other sites More sharing options...
lalabored Posted June 24, 2007 Author Share Posted June 24, 2007 Oh, okay, thanks. Link to comment https://forums.phpfreaks.com/topic/56001-solved-why-does-this-happen/#findComment-281181 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.