kendallkamikaze Posted April 24, 2009 Share Posted April 24, 2009 can anyone tell me why this code conflicts with browsers such as Opera? <SCRIPT LANGUAGE=JavaScript> function CheckAll() { count = document.frm.elements.length; for (i=0; i < count; i++) { if(document.frm.elements[i].checked == 1) {document.frm.elements[i].checked = 0; } else {document.frm.elements[i].checked = 1;} } } function UncheckAll(){ count = document.frm.elements.length; for (i=0; i < count; i++) { if(document.frm.elements[i].checked == 1) {document.frm.elements[i].checked = 0; } else {document.frm.elements[i].checked = 1;} } } </script> the rest of the code is: <?php if($_GET[action] == "delete"){print "The selected messages were deleted.<br><a href=messages2.php>Go Back.</a>";} print " <br><Br><form name='frm' method='post' action='messages2.php?action=delete'> <input type='submit' name='massdelete' value='Delete Selection'>"; ?> <div id="tableContainer" class="tableContainer"> <table width=630 border="0" cellpadding="0" cellspacing="0"> <tr><td> <table border="0" cellpadding="0" cellspacing="0" > <tr height=19px> <td class='maintable' height=19px style='background-image: url(http://i43.tinypic.com/2eundbq.jpg);background-repeat: no-repeat; background-position: center center;'><img src='http://i43.tinypic.com/2eundbq.jpg'></td> <td class='maintable' height=19px width=32> <input type='checkbox' name='btn' onclick='CheckAll()'/> </td> <td class='maintable' height=19px width=50 style='background-image: url(http://i41.tinypic.com/2yw60r6.jpg);'> From</td> <td class='maintable' width=235 style='background-image: url(http://i41.tinypic.com/2yw60r6.jpg);'> |Subject</td> <td class='maintable' width=235 style='background-image: url(http://i41.tinypic.com/2yw60r6.jpg);'> |Date</td> <td class='maintable' height=19px style='background-image: url(http://i41.tinypic.com/2yw60r6.jpg);'> |Status</td> <td class='maintable' height=19px style='background-image: url(http://i41.tinypic.com/2yw60r6.jpg);'> </form></td> <td class='maintable' height=19px style='background-image: url(http://i43.tinypic.com/2eundbq.jpg);background-repeat: no-repeat; background-position: center center;'><img src='http://i43.tinypic.com/2eundbq.jpg'></td> </tr> </table> </td></tr> <tr><td> <table width=635 border="0" cellpadding="0" cellspacing="0" > <tbody class="scrollContent"> <?php $sql="SELECT * FROM messages WHERE Recipient='$id' order by id desc "; $result=mysql_query($sql); $msgs=mysql_num_rows($result); $checkbox = $_POST['checkbox']; if(!empty($checkbox)){ $massdelete = $_GET['massdelete']; if(massdelete){ for($i=0;$i<$msgs;$i++){ $deleteid = $checkbox[$i]; mysql_query("delete from messages where id='$deleteid'"); //echo ("$checkbox<br>"); //display all msg ids deleted } }} //and new='yes' if($msgs == "0"){ print "<tr><td colspan=5><center>No Messages.</td></tr>"; } for($i=0;$i<$msgs;$i++) { $r=mysql_fetch_array($result); $mid=$r["id"]; $Sender=$r["Sender"]; $Subject=$r["Subject"]; $Message=$r["Message"]; $Date=$r["date"]; $New=$r["new"]; if($New == "no"){$rou="Read";} if($New == "yes"){$rou="Unread";} if(empty($Subject)){$Subject="No Subject";} //Sunday 6/18/2008 2:38pm //$Date=str_replace(D n/j/y g:ia,$Date); echo " <tr class='msg' class='scrollContent' onMouseOver=this.className='highlight' onMouseOut=this.className='msg'> <td width=29><input type=checkbox name='checkbox[]' value='$mid'></form></td> <td width=57><b><a href=player_individual.php?id=$Sender>#$Sender</a></b></td> <td width=235><b><a href='message_viewindividual.php?id=$mid'>$Subject</a></b></td> <td width=230><i>$Date</i></td> <td><center><b>$rou</b></center></td> </tr> "; } ?> </table> </td></tr> </tbody> </table></div> <BR><BR> <?php include "footer.php"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/155447-script-conflict-with-browsers/ Share on other sites More sharing options...
darkfreaks Posted April 24, 2009 Share Posted April 24, 2009 when your calling functions within the html its proper to end them with semicolons Quote Link to comment https://forums.phpfreaks.com/topic/155447-script-conflict-with-browsers/#findComment-817984 Share on other sites More sharing options...
kendallkamikaze Posted April 24, 2009 Author Share Posted April 24, 2009 alright, so now that those are added, you're able to check the box...but it doesnt select all of the checks when you click the check all portion? Quote Link to comment https://forums.phpfreaks.com/topic/155447-script-conflict-with-browsers/#findComment-817991 Share on other sites More sharing options...
darkfreaks Posted April 24, 2009 Share Posted April 24, 2009 Try: function checkAll(field) { for (i = 0; i < field.length; i++) field[i].checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field[i].checked = false ; } <form name="myform" action="checkboxes.asp" method="post"> <b>Your Favorite Scripts & Languages</b><br> <input type="checkbox" name="list" value="1">Java<br> <input type="checkbox" name="list" value="2">Javascript<br> <input type="checkbox" name="list" value="3">Active Server Pages<br> <input type="checkbox" name="list" value="4">HTML<br> <input type="checkbox" name="list" value="5">SQL<br> <input type="button" name="CheckAll" value="Check All" onClick="checkAll(document.myform.list)"> <input type="button" name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(document.myform.list)"> <br> Quote Link to comment https://forums.phpfreaks.com/topic/155447-script-conflict-with-browsers/#findComment-818009 Share on other sites More sharing options...
kendallkamikaze Posted April 24, 2009 Author Share Posted April 24, 2009 well now. that works with the buttons, but i need it to work with a check box? Quote Link to comment https://forums.phpfreaks.com/topic/155447-script-conflict-with-browsers/#findComment-818113 Share on other sites More sharing options...
RichardRotterdam Posted April 24, 2009 Share Posted April 24, 2009 You could do that by using just one function. Pass the checked status of the checkbox (untested) <script> function changeCheckStat(field,status) { for (i = 0; i < field.length; i++){ field[i].checked = status ; } } </script> <input type="checkbox" name="CheckAll" value="Check All" onClick="changeCheckStat(document.myform.list,this.checked)"> Quote Link to comment https://forums.phpfreaks.com/topic/155447-script-conflict-with-browsers/#findComment-818127 Share on other sites More sharing options...
Axeia Posted April 24, 2009 Share Posted April 24, 2009 Doh, got confused by the code the OP posted. The uncheck all function is never used and the CheckAll is a toggle instead of checking all.. In that case the poster above is right. Code below is what I ended up writing and which is useless I guess unless you actually wanted to do what the function names indicated. <script type='text/javascript'> function ChangeTo( valBool ) { var inputs = document.frm.getElementsByTagName( 'input' ); for ( var i = 0; i < inputs.length; i++) if( inputs[i].type ) if( inputs[i].type == 'checkbox' ) if( inputs[i].checked != valBool ) inputs[i].checked = valBool; } function CheckAll() { ChangeTo( true ); } function UncheckAll() { ChangeTo( false ); } </script> Quote Link to comment https://forums.phpfreaks.com/topic/155447-script-conflict-with-browsers/#findComment-818195 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.