Jump to content

script conflict with browsers


kendallkamikaze

Recommended Posts

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";

?>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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)">

Link to comment
Share on other sites

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>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.