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 7 of 7
  1. #1
    New Coder
    Join Date
    Sep 2008
    Posts
    66
    Thanks
    18
    Thanked 0 Times in 0 Posts

    why this javascript code is not executing

    Hi,

    I am wondering the following javascript code is not able to execute. In my JSP table i have no.of rows are there. In my logic there is for loop to display all rows in table. In that table i have 8 columns. by default i need to heilight the row. I wrote the following logic at 2nd column of the table.
    Code:
          <td class=verySmall valign=middle nowrap name="taskname" id='TD_TASK_<%=t.getID()%>'><div id='divTaskName_<%=t.getID()%>:divParentTask_<%=t.getParentTaskId()%>'  onClick="OZ_openBrWin2('ozPrjTaskDtl.jsp?id=<%=t.getID()%> ','prjEdit','width=780,height=580');" oncontextmenu="return contextMenuCursor( event, 'PRJEDIT', '<%=t.getID()%>', '<%=t.getID()%>' );" class=dragclass><a href="#" ><%=AhsStringUtil.limitLength(t.getName(),60)%></a></div></td>
        <%
            if (i==0)
            {
                System.out.println("1st Task ID"+t.getID());
        %>
           <script type="text/javascript">
               alert('*******');
               var _gOldHightlightTaskId = -1;
               var _gTaskId = -1;
               alert('_gTaskId'+<%=t.getID()%>);
               function prjtask(<%=t.getID()%>)
               {
                    alert('TASK ID'+<%=t.getID()%>);
                    if ( _gOldHightlightTaskId > 0 && $('TD_TASK_'+_gOldHightlightTaskId) != null )
                    {
                        $( 'TR_LINE_'+_gOldHightlightTaskId ).bgColor='FFFFFF';
                    }
    
                    _gOldHightlightTaskId = <%=t.getID()%>;
                    _gTaskId = <%=t.getID()%>;
                    if ( _gOldHightlightTaskId > 0 && $('TD_TASK_'+_gOldHightlightTaskId) != null )
                    {
                        $( 'TR_LINE_'+_gOldHightlightTaskId ).bgColor='FFA500';
                    }
                    refreshDetailTab();
                    PositionTip(<%=t.getID()%>);
               }
           </script>
        <%
            }
        %>
        <td class=verySmall valign=middle nowrap>
    I am not getting the alert statements.

    thanks in advance.
    Last edited by adusumalli; 07-14-2009 at 09:32 PM.

  • #2
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    Well in fact there are plenty of errors in this file and they need to be re-written from scratch.

    I will point to some of them:
    you have put the script tag inside a jsp if :
    if (i==0)
    {
    System.out.println("1st Task ID"+t.getID());
    <if (i==0)
    {
    System.out.println("1st Task ID"+t.getID());
    >etc....</script>
    }

    so it won't enter in it unless i == 0

    besides you are using the $ sign and this does not exist in jsp.

    By the way the browser should throw a script error.

    What web server you are using?

  • #3
    New Coder
    Join Date
    Sep 2008
    Posts
    66
    Thanks
    18
    Thanked 0 Times in 0 Posts
    I am using Tomcat. Actually for 1st row that the 'i' value should be '0' . I need to execute this js logic on 1st row of the table. Actually i need to execute this js method. This js method is for heilighting the row of the table when row is selected. but i want to execute this js method by default on 1st row. in for loop when i=0 then the 1st row values are getting. that's i check the condition like if (i==0)
    Code:
      function changeContext( taskId )
      {
        if ( _gOldHightlightTaskId > 0 && $('TD_TASK_'+_gOldHightlightTaskId) != null )
        {
           $( 'TR_LINE_'+_gOldHightlightTaskId ).bgColor='FFFFFF';
        }
    
        _gOldHightlightTaskId = taskId;
        _gTaskId = taskId;
        if ( _gOldHightlightTaskId > 0 && $('TD_TASK_'+_gOldHightlightTaskId) != null )
        {
            $( 'TR_LINE_'+_gOldHightlightTaskId ).bgColor='FFA500';
        }
        refreshDetailTab();
        PositionTip(taskId);
      }
    thanks.

  • #4
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    I understood your need.

    But the way you are writing the code is not accurate for jsp.

    I am sure there will be script errors.

    I do not know any PHP but I smell some php inside it.

    Can you please explain to me what do you mean by
    $( 'TR_LINE_'+_gOldHightlightTaskId ).bgColor='FFA500';

    besides the way you are putting the if you are not preventing the browser from executing but you are not declaring the method at all.

  • #5
    New Coder
    Join Date
    Sep 2008
    Posts
    66
    Thanks
    18
    Thanked 0 Times in 0 Posts
    hi sorry for delay. I was on leave yesterday. Actual my page is one.jsp , In my one.jsp i have no. of rows records are there with 7 -8 columns. This table rows are in two.jsp. i.e two.jsp is calling from one.jsp throw Ajax. Now all rows are displaying properly.

    In one.jsp, I have the following js methods: First time when open this these js methods are invoking.
    Code:
    function refreshAndInit()
      {
        if ( $('divTaskName_0')!=null )
        {
          $('newtaskinline').style.position = "absolute";
          $('newtaskinline').style.top  = getAbsElementYById( 'divTaskName_0' );
          $('newtaskinline').style.left = getAbsElementXById( 'divTaskName_0' ) - 4;
          $('newtaskinline').value = '';
        }
         fcCalRefreshInProgress = 0;
        _gTextMode = 1;
        _gTextMode2TaskId = 0;
    
        changeContext( _gTaskId);  // here _gTaskId is -1 first time. 
      }
    
    function changeContext( taskId )
      {
        if ( _gOldHightlightTaskId > 0 && $('TD_TASK_'+_gOldHightlightTaskId) != null )
        {
           $( 'TR_LINE_'+_gOldHightlightTaskId ).bgColor='FFFFFF';
        }
    
        _gOldHightlightTaskId = taskId;
        _gTaskId = taskId;
        if ( _gOldHightlightTaskId > 0 && $('TD_TASK_'+_gOldHightlightTaskId) != null )
        {
            $( 'TR_LINE_'+_gOldHightlightTaskId ).bgColor='FFA500';
        }
        refreshDetailTab();
        PositionTip(taskId);
      }
    As u asked $( 'TR_LINE_'+_gOldHightlightTaskId ).bgColor='FFA500';

    'TR_LINE_<%=t.getID()%>' is the row ID of table rows. and 'FFA500' is one of the gray color. The following statement is there in two.jsp . from the following statement the table rows are started. and it's there in for loop.

    Code:
    <tr id="TR_LINE_<%=t.getID()%>"  bgcolor="#FFFFFF"  onClick="changeContext(<%=t.getID()%>);" >
    Now what's happening is when i select any row that row is heilighting. when i click on the row this changeContext(<%=t.getID()%>) is calling from above <tr> and passing the task id which is the one i selected.

    but now what my requirement is i need to select first row by default and need to pass 1st row task id. how do i pass task id and how do i call that "changeContext()" ??

  • #6
    New Coder
    Join Date
    Sep 2008
    Posts
    66
    Thanks
    18
    Thanked 0 Times in 0 Posts
    duplicate post
    Last edited by adusumalli; 07-17-2009 at 12:29 AM.

  • #7
    New Coder
    Join Date
    Sep 2008
    Posts
    66
    Thanks
    18
    Thanked 0 Times in 0 Posts
    hi did you get my point ?


  •  

    Posting Permissions

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