...

View Full Version : why this javascript code is not executing



adusumalli
07-14-2009, 09:24 PM
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.


<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.

ckeyrouz
07-14-2009, 10:01 PM
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?

adusumalli
07-14-2009, 10:14 PM
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)


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.

ckeyrouz
07-15-2009, 07:08 AM
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.

adusumalli
07-16-2009, 05:58 PM
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.


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.


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

adusumalli
07-16-2009, 05:58 PM
duplicate post

adusumalli
07-17-2009, 11:30 PM
hi did you get my point ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum