Forum Moderators: open

Message Too Old, No Replies

javascript error in IE

         

thamps

11:12 am on Jul 26, 2005 (gmt 0)

10+ Year Member



hai,

i am working in jsp application . in that i am calling a java script method onClick event of an image.
its working fine with Mozilla browser. but showing error in IE.

The code is as follows,

<td><a href ="javascript:return(true)" onclick="javascript:loadPlugins('<%=save%>')"><img src="../user/resources/images/btn_save.gif" border="0"></a></td>
<td><a href="javascript:retrun(true)" onclick="javascript:loadPlugins('<%=cancel%>')"><img src="../user/resources/images/btn_cancel.gif" border="0" ></a> </td>

the Javascript is as follows

function loadPlugins(act){
var action=act;
if (action=="SAVE"){
document.forms[0].action.value="SAVE";
if(parent.pluginFrame.document.forms[0].oldfamilyid.value){
parent.pluginFrame.document.forms[0].actions.value="SAVE";
parent.pluginFrame.document.forms[0].action="/sas/user/saveplugins.do";
parent.pluginFrame.document.forms[0].submit();
}else{
alert(" No Plugins are selected");

}
}else{
parent.pluginFrame.document.forms[0].actions.value="CANCEL";
parent.pluginFrame.document.forms[0].submit();

}

return ;
}

IE gives the following javascript error return is outside the function

can any one suggest a solution for this

tedster

5:48 pm on Jul 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The second line in your html has a typo -- retrun instead of return

thamps

9:49 am on Jul 27, 2005 (gmt 0)

10+ Year Member



hi tedster,
this is in response to the reply you send to my topic with subject "javascript error in IE ". thanks for the information you provided. I am getting the error again..

i am sending the code again plz. go through it.

<td class="pluginfamily" ><a href="javascript:return( true)" onclick="javascript:loadPlugins(<%=id%>);" target="pluginFrame"><%=family.getName()%></a></td>

function loadPlugins(id){

if(parent.pluginFrame.document.forms[0].oldfamilyid.value){
parent.pluginFrame.document.forms[0].newfamilyid.value=id;
parent.pluginFrame.document.forms[0].submit();
}else{

parent.pluginFrame.document.forms[0].newfamilyid.value=id;
parent.pluginFrame.document.forms[0].submit();
}
return ;
}

I checked the javascript console of Mozilla its giving an error as follows.

Error: invalid return;
Source:javascript:return(true);
return(true)

even though its giving error in Mozilla browser the form is getting submitted and working fine. but the same thing is not working in IE . In IE its giving a javascript error retrun is out of the function.

I have used the javascript:return(true) method in some other jsp also. there also I am facing the same problem.

looking forward for a solution....

tedster

6:19 pm on Jul 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, I think the error is saying that parser ended the definition of your function loadPlugins() before the return was reached. It looks to me like there's some odd nesting of your curly braces and I can't quite put my finger on what is going on with the logic of the if statements - I marked the open braces in blue and the closing braces in red

function loadPlugins(act){
var action=act;
if (action=="SAVE"){
document.forms[0].action.value="SAVE";
if(parent.pluginFrame.document.forms[0].oldfamilyid.value){
parent.pluginFrame.document.forms[0].actions.value="SAVE";
parent.pluginFrame.document.forms[0].action="/sas/user/saveplugins.do";
parent.pluginFrame.document.forms[0].submit();
}else{
alert(" No Plugins are selected");

}
}
else{
parent.pluginFrame.document.forms[0].actions.value="CANCEL";
parent.pluginFrame.document.forms[0].submit();

}

return ;
}

Shouldn't it be something like this, closing the action for the first "if" before the next one opens?

function loadPlugins(act){
var action=act;
if (action=="SAVE"){
document.forms[0].action.value="SAVE";}
if(parent.pluginFrame.document.forms[0].oldfamilyid.value){
parent.pluginFrame.document.forms[0].actions.value="SAVE";
parent.pluginFrame.document.forms[0].action="/sas/user/saveplugins.do";
parent.pluginFrame.document.forms[0].submit();
}else{
alert(" No Plugins are selected");

}
else{
parent.pluginFrame.document.forms[0].actions.value="CANCEL";
parent.pluginFrame.document.forms[0].submit();

}

return ;
}