bugfinder Posted May 17, 2009 Share Posted May 17, 2009 Good day everybody, i guess i have issue with my code i get 'selected is null' or not an object error can some one help me out with this .. lines 128 and 155 <? include('config.php'); include('connect.php'); include('checkusersession.php'); if (!isset($target_type)) $target_type = 'all'; ?> <form name='form_allocate_terminals'> <table border="0" cellpadding="4" cellspacing="4" width="50%" align="center" class="tableForm"> <tr > <td align="left" valign="middle" width="3%" > <font color="#000000"><strong>Type:</strong></font> </td> <td align="left" valign="middle" colspan="5"> <select name="message" > <? $sqlMsg = "SELECT * FROM `".$DBTablesPrefix."_emergency_type`"; $Infos = mysql_query($sqlMsg) or die("Query Failed 1"); $j = 0; while($Row_Infos = mysql_fetch_assoc($Infos)) { $j++; $Id = $Row_Infos['Id']; $name = $Row_Infos['name']; echo "<option value='".$Id."' ".$strSelected.">".$name; } ?> </select> </td> </tr> <tr bgcolor="#ECECEC" > <td align="left" valign="middle" width="3%" colspan="4"> <input type="radio" name="target_type" value="all" <?=($target_type=="all")?"checked":""?> onClick="disableItems(this);"> <font color="#000000" size="2"><strong>All</strong></font> </td> </tr> <tr bgcolor="#ECECEC"> <td align="left" valign="middle" width="3%" colspan="4"> <input type="radio" name="target_type" value="room" <?=($target_type=="room")?"checked":""?> onClick="disableItems(this);"> <font color="#000000" size="2"><strong>Rooms</strong></font> </td> </tr> <tr > <td align="left" valign="middle" width="30%"> <select name="target_list[]" id ='target_list' size="3" multiple style="width:100 "> <? //terminal identification in multi-terminal rooms $query ="SELECT IP, Room FROM `".$DBTablesPrefix."_stbs`"."WHERE Version='aminet110' "." ORDER BY Room "; $Infos = mysql_query($query) or die("Query failed on line 188"); $i = 0; while($Row_Infos = mysql_fetch_array($Infos)) { $i++; $IP = $Row_Infos['IP']; $Room = $Row_Infos['Room']; $messRoom = Room; //echo "<option value='".$Room[$i]."' ".$strSelected.">".$Room."::".$IP."\r\n"; echo "<option value='".$Room[$i]."' ".$strSelected.">$messRoom ".$Room." \r\n"; } ?> </select> </td> <td width="10%" align="center" valign="middle"> <input type="hidden" name="action" value="add"> <table border="0"> <tr align="center" height="50%"> <td width="30%"> <? echo '<img src="../admin/img/right.gif" border="0"><img src="../admin/img/right.gif" border="0">'; ?> </td> <td> <input type="button" onClick='movein()' value="Add"> </td> <td width="30%"> <? echo '<img src="../admin/img/right.gif" border="0"><img src="../admin/img/right.gif" border="0">'; ?> </td> </tr> <tr align="center" height="50%"> <td width="30%"> <? echo '<img src="../admin/img/left.gif" border="0"><img src="../admin/img/left.gif" border="0">'; ?> </td> <td> <input type="button" onClick="moveout()" value="Remove"> </td> <td width="30%"><? echo '<img src="../admin/img/left.gif" border="0"><img src="../admin/img/left.gif" border="0">';?> </td> </tr> </table> </td> <td align="right" width="30%"> <select name="allocatedTerminals[]" id='allocatedTerminals' size="3" multiple style="width:100 " > </select> </td> </tr> <tr align="center" > <td colspan="4"><input type="button" name='btnSend' value="Send" onClick="sendemergency(form_allocate_terminals)"> <!-- <input name="btnsend" type="button" class="buttform" id="34" value="Send Emergency" onclick="pushpage()" />--></td> </tr> </table> </form> <script language="javascript"> var cmdLink = "EMERGENCY_execcommand.php?Emergency=<?php echo $name;?>&targetType=<?php echo $target_type;?>&ip=<?php echo $IP;?>"; function pushpage() { Link = cmdLink+" SEND"; //alert(Link); var msg = "Are you sure you want to delcare Emergency?"; if(confirm(msg)) document.location.href=""+Link; } function movein() { var target_list = document.getElementById('target_list');; var allocated_terminal = document.getElementById('allocatedTerminals'); var target_list_length = target_list.length; for(var j=0; j<target_list_length; j++) { if(target_list[j].selected) //this is where im getting error msg { var tmp = target_list.options[j].text; var tmp1 = target_list.options[j].value; target_list.remove(j); j--; var y=document.createElement('option'); y.text=tmp; try { allocated_terminal.add(y,null); } catch(ex) { allocated_terminal.add(y); } } } } function moveout() { var target_list = document.getElementById('target_list'); var allocated_terminal = document.getElementById('allocatedTerminals'); var allocated_terminal_length = allocated_terminal.length; for(var j=0; j<allocated_terminal_length; j++) { if(allocated_terminal[j].selected) //this is where im getting error msg { var tmp = allocated_terminal.options[j].text; var tmp1 = allocated_terminal.options[j].value; allocated_terminal.remove(j); j--; var y=document.createElement('option'); y.text=tmp; try { target_list.add(y,null); } catch(ex) { target_list.add(y); } } } } function disableItems(selectedItem) { if (selectedItem.value =='all') { document.getElementById("target_list").disabled = true; document.getElementById("allocatedTerminals").disabled = true; } else if(selectedItem.value =='room') { document.getElementById("target_list").disabled = false; document.getElementById("allocatedTerminals").disabled = false; } } window.onload=function() { var targetType = '<? echo $target_type;?>'; if (targetType =='all') { document.getElementById("target_list").disabled = true; document.getElementById("allocatedTerminals").disabled = true; } else if(targetType =='room') { document.getElementById("target_list").disabled = false; document.getElementById("allocatedTerminals").disabled = false; } } function sendemergency() { var len =document.form_allocate_terminals.target_type.length; for (i=0;i<len;i++) { if(document.form_allocate_terminals.target_type.checked) { alert("Do you really want to send the emergency"); } } } </script> <?php $action =send; if ($btnSend ==$action) { $pause = 5; $sqlMsg = "SELECT * FROM `".$DBTablesPrefix."_emergency_type`"; $Infos = mysql_query($sqlMsg) or die("Query failed on line 55"); $j = 0; while($Row_Infos = mysql_fetch_assoc($Infos)) { $j++; $Id= $Row_Infos['Id']; $msg= $Row_Infos['message']; if ($Id == $message) { $display_message = $msg; } } $commandURL = "../emergency/simple_remote_control.php?message=".urlencode(stripslashes($display_message)); $cmdOptions = "/PASSWORD \"".$aminoRemoteControlPassPhrase."\" /TIMEOUT 12 /THREADS 60 /PAUSE ".$pause." /QUIET"; $cmdCommand = "/LOADURL ".EMERGENCY_PATH."simple_emergency_message.php"."?message=".urlencode(stripslashes($display_message)); $cmdFile = "/FILE \"".$tIpListFiles[$TERM_TYPE_AMINET100][0]."\""; if ($target_type == 'all') { $sqlTerminals = "SELECT IP, Room FROM `".$DBTablesPrefix."_stbs`"." WHERE Version='AMINET110' "."ORDER BY (Room+0)"; $Infos = mysql_query($sqlTerminals) or die("Query failed on line 78"); $i = 0; while($Row_Infos = mysql_fetch_assoc($Infos)) { $i++; $termIP = $Row_Infos['IP']; $termRoom = $Row_Infos['Room']; $cmdLine = "AminoBatchControl.exe ".$cmdCommand." ".$cmdOptions." ".' TERMINALCHANGE '.$termIP; exec( $cmdLine, $cmdOutput); } } else if ($target_type == 'room') { for ($i = 0; $i< count($Room); $i++) { $sqlTerminals = "SELECT IP, Room FROM `".$DBTablesPrefix."_stbs` ". "WHERE `Room` = '$Room[$i]'"; $Infos = mysql_query($sqlTerminals) or die("Query failed in line 95"); if ($sqlTerminals > 0) while($Row_Infos = mysql_fetch_assoc($Infos)) { $IP_terminal = $Row_Infos['IP']; $cmdLine = "AminoBatchControl.exe ".$cmdCommand." ".$cmdOptions." ".' TERMINALCHANGE '.$IP_terminal; //echo $cmdLine; exec( $cmdLine, $cmdOutput ); } } } } ?> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 17, 2009 Share Posted May 17, 2009 Can you post lines 128 and 155 rather than all that? document.getElementById() returns one result. As a general rule, you shouldn't have more than one of the same ID on the same page. It's HTML. Fix it or change it to a class. Quote Link to comment Share on other sites More sharing options...
bugfinder Posted May 17, 2009 Author Share Posted May 17, 2009 Sure function movein() { var target_list = document.getElementById('target_list');; var allocated_terminal = document.getElementById('allocatedTerminals'); var target_list_length = target_list.length; for(var j=0; j<target_list_length; j++) { if(target_list[j].selected) //this is where im getting error msg { var tmp = target_list.options[j].text; var tmp1 = target_list.options[j].value; target_list.remove(j); j--; var y=document.createElement('option'); y.text=tmp; try { allocated_terminal.add(y,null); } catch(ex) { allocated_terminal.add(y); } } } } function moveout() { var target_list = document.getElementById('target_list'); var allocated_terminal = document.getElementById('allocatedTerminals'); var allocated_terminal_length = allocated_terminal.length; for(var j=0; j<allocated_terminal_length; j++) { if(allocated_terminal[j].selected) //this is where im getting error msg { var tmp = allocated_terminal.options[j].text; var tmp1 = allocated_terminal.options[j].value; allocated_terminal.remove(j); j--; var y=document.createElement('option'); y.text=tmp; try { target_list.add(y,null); } catch(ex) { target_list.add(y); } } } } i commented the line 128 and 155 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.