Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation selected is null or not an object

    Good day every body i have issue with my script can any one check this for me i use IE 6 and i get
    selected is null or not an object
    error

    Code:
    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);	
    			}
    
    		}
    	}	
    }
    PHP Code:
    <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>

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    So you did this -

    var tmp = target_list.options[j].text;
    var tmp1 = target_list.options[j].value;


    ... properly checking each option object ... but before that. you did:

    if(target_list[j].selected)

    ... checking for a 'selected' property of the Select object. No such thing; there is a 'selectedIndex' property, but with a multiple, you'll just get the first. Iterate over the options:

    if(target_list.options[j].selected)

    You php people & your square brackets ....

    Edit: Just for the record, Select[n] is OK, the equivalent of Select.options[n]. Typical DOM shorthand, stupid of me to forget it.
    Last edited by adios; 05-18-2009 at 01:44 PM.

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for ur reply im not a Core JS programmer ... im trying out with some of examples on the internet ...!!!
    I still get the same error ..!! Any suggestion..??

  • #4
    New to the CF scene
    Join Date
    May 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs down NO gooo..!!!

    What you told didn't work

  • #5
    New to the CF scene
    Join Date
    May 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    i Get this error now
    Error:-options[...] is null or not an object

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    1) • View source • on the page in question and post it here.
    2) Or: put it on your server and post a link.

  • #7
    New to the CF scene
    Join Date
    May 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer Here is the code

    here is the code u asked for ...

    PHP Code:
    <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" >
                <
    option value='43' >Fire<option value='44' >Attention           </select>            
            </
    td>
      </
    tr>    
      <
    tr bgcolor="#ECECEC" >
                <
    td align="left" valign="middle" width="3%" colspan="4">
                <
    input type="radio" name="target_type" value="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"  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 ">
                <
    option value='6' >Room 663 
    <option value='' >Room 99 
              
    </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%">
                            <
    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%">
                        <
    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%">
                            <
    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%"><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=Attention&targetType=all&ip=10.11.1.4";
    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=0j<target_list_lengthj++)
        {
            if(
    target_list.options[j].selected)
            
    //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=0j<allocated_terminal_lengthj++)
        {
            if(
    allocated_terminal.options[j].selected)
            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 'all';
        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 emergency");
     }
    }
    }
    </script>
    :( 

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    When you decrement the loop counter:

    j--;

    ... you'll also need to decrement the counter limit:

    target_list_length--
    j--;


    ... and in the other function:

    allocated_terminal_length--;
    j--;


    ... otherwise you'll go out of bounds. As I said, these:

    if(target_list.options[j].selected)
    if(allocated_terminal.options[j].selected)

    ... are correct.

    One other thing - radio buttons tend to have persistence, so you might want to run the onclick handler of the appropriate 'target_type' radio each time the page loads:

    window.onload = function()
    {
    var target_type = document.form_allocate_terminals.elements['target_type'];
    for (var i = 0; i < target_type.length; i++)
    {
    if (target_type[i].checked)
    {
    target_type[i].onclick();
    }
    }
    }


    Keeps things in sync ...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •