By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,481 Members | 1,211 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,481 IT Pros & Developers. It's quick & easy.

javascript working on mozilla firefox but not on IE 6

P: 41
Hi,

I have the following script

Expand|Select|Wrap|Line Numbers
  1. function submitForm1()
  2. {
  3.    document.forms[0].action="SearchRecords";
  4.    document.forms[0].submit();
  5. }
[HTML]<select name="l" onchange="submitForm1();">[/HTML]

This script is working on firefox but not in IE6.
Can anybody tell me why this is happening and the alternative solution to perform the same function.

Thanks
Oct 29 '07 #1
Share this Question
Share on Google+
26 Replies


P: 41
Hi,

I have the following script


Expand|Select|Wrap|Line Numbers
  1. function submitForm1()
  2. {
  3.    document.forms[0].action="SearchRecords";
  4.    document.forms[0].submit();
  5. }
  6.  

[HTML]<select name="l" onchange="submitForm1();">[/code][/HTML]


This script is working on firefox but not in IE6.
Can anybody tell me why this is happening and the alternative solution to perform the same function.

Thanks
Oct 29 '07 #2

10K+
P: 13,264
Hi,

I have the following script

Expand|Select|Wrap|Line Numbers
  1. function submitForm1()
  2. {
  3.    document.forms[0].action="SearchRecords";
  4.    document.forms[0].submit();
  5. }
[HTML]<select name="l" onchange="submitForm1();">[/HTML]

This script is working on firefox but not in IE6.
Can anybody tell me why this is happening and the alternative solution to perform the same function.

Thanks
Java != Javascript

Moved to Javascript forum
Oct 29 '07 #3

gits
Expert Mod 5K+
P: 5,390
threads merged ... since they cover the same topic/question ...
Oct 29 '07 #4

acoder
Expert Mod 15k+
P: 16,027
So what happens in IE? Any errors?
Oct 29 '07 #5

P: 41
So what happens in IE? Any errors?
Hi,
There is neither any response nor any error means it does not call SearchRecords at all.

Thanx
Oct 30 '07 #6

acoder
Expert Mod 15k+
P: 16,027
There is neither any response nor any error means it does not call SearchRecords at all.
Is 'SearchRecords' a valid server file?

You're using forms[0]. Is there only one form in the page?
Oct 30 '07 #7

P: 41
Is 'SearchRecords' a valid server file?

You're using forms[0]. Is there only one form in the page?
Hi,

There is only one form and also SearchRecords is valid after all this is working on Firefox.
Is it possible that we have to make some changes in settings of IE?If yes, what will be those settings.

Thanks
Oct 30 '07 #8

acoder
Expert Mod 15k+
P: 16,027
Can you post the rest of the code or a link? If the code is too long, post the relevant parts.
Oct 30 '07 #9

P: 41
Can you post the rest of the code or a link? If the code is too long, post the relevant parts.
Hi,
Thax for ur consideration. but I think the code in original post is sufficient to find the error. In this I have one dropdown and based on that I call the javascript function that sets the action attribute for the form and submits it to that servlet.

Thanks
Oct 30 '07 #10

rizwan6feb
100+
P: 108
There is nothing wrong with the original code, even if IE6 is being used. There can be error in the code above these two statements:

Expand|Select|Wrap|Line Numbers
  1. document.forms[0].action="SearchRecords";
  2. document.forms[0].submit();
  3.  
which is causing the form not to submit. Try using alert functions to debug the statements above the form submission code
Oct 30 '07 #11

P: 41
There is nothing wrong with the original code, even if IE6 is being used. There can be error in the code above these two statements:

Expand|Select|Wrap|Line Numbers
  1. document.forms[0].action="SearchRecords";
  2. document.forms[0].submit();
  3.  
which is causing the form not to submit. Try using alert functions to debug the statements above the form submission code
Hi,
I have tried both of the following

Expand|Select|Wrap|Line Numbers
  1. function submitForm1()
  2. {
  3. alert("hvgfjh");
  4.    document.forms[0].action="SearchRecords";
  5.    document.forms[0].submit();
  6. }
Expand|Select|Wrap|Line Numbers
  1. function submitForm1()
  2. {
  3.    document.forms[0].action="SearchRecords";
  4. alert("hvgfjh");
  5.    document.forms[0].submit();
  6. }
In IE6
In first one the alert box works but in second no alert box appears.
In IE7
But both are working on IE7

Thanks
Oct 30 '07 #12

P: 41
Hi,
I have tried both of the following

Expand|Select|Wrap|Line Numbers
  1. function submitForm1()
  2. {
  3. alert("hvgfjh");
  4.    document.forms[0].action="SearchRecords";
  5.    document.forms[0].submit();
  6. }
Expand|Select|Wrap|Line Numbers
  1. function submitForm1()
  2. {
  3.    document.forms[0].action="SearchRecords";
  4. alert("hvgfjh");
  5.    document.forms[0].submit();
  6. }
In IE6
In first one the alert box works but in second no alert box appears.
In IE7
But both are working on IE7

Thanks
Hi,

Its working in case of radiobutton but not on onchange event of dropdown.

Thanks
Oct 30 '07 #13

P: 41
Hi,

Its working in case of radiobutton but not on onchange event of dropdown.

Thanks
Hi,

Sorry for the previous post.
Please ignore the previous reply because it works for both radiobutton and dropdown in IE 7 but not with IE 6.

Thanks
Oct 30 '07 #14

P: 41
Hi,

Sorry for the previous post.
Please ignore the previous reply because it works for both radiobutton and dropdown in IE 7 but not with IE 6.

Thanks
Hi,

The complete code is as below
Expand|Select|Wrap|Line Numbers
  1. <%@ page import="java.util.ArrayList"%>
  2. <%@ page import="javax.servlet.*"%>
  3. <%@ page import="javax.servlet.http.*"%>
  4.  
  5. <html>
  6. <head>
  7. <title> Form </title>
  8. <script language="javascript" type="text/javascript">
  9.  
  10. function submitForm1()
  11. {
  12.  
  13.    document.forms[0].action="SearchRecords";
  14.    alert("fghfhfhf");
  15.  
  16.    document.forms[0].submit();
  17. }
  18.  
  19. function submitForm2()
  20. {
  21. document.forms[0].action="Search";
  22. document.forms[0].submit();
  23. }
  24. </script>
  25.  
  26. <%
  27. ArrayList al=(ArrayList)session.getAttribute("str_");
  28. %>
  29.  
  30.  
  31. </head>
  32.  
  33.  
  34.  
  35. <body bgcolor="fuschia">
  36.  
  37.  
  38.  
  39. <center>
  40.  
  41.     <font size=7 color="red"> Please Enter the following information: </font>
  42.        <form name="form1" method="POST">
  43.  
  44.            <table cellspacing="2" cellpadding="2" border="0">
  45.                <tr>
  46.            <td><input type="hidden" name="role" id="role"></td>
  47.             </tr>
  48.  
  49.         <tr>
  50.         <td align="left"><font size=5>Last Name</font></td>
  51.         <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=text name="sn" value="<%=request.getAttribute("lname") %>"></td>
  52.         </tr>
  53.  
  54.         <tr>
  55.         <td align="left"><font size=5>FullName</font></td>
  56.         <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=text name="cn" value="<%=request.getAttribute("fname")%>"><td>
  57.         </tr>
  58.  
  59.         <tr>
  60.         <td align="left"><font size=5>Location</font></td>
  61.         <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  62.         <select name="l" onchange="submitForm1();">
  63.         <%if(request.getAttribute("location")!=null)%>
  64.         <Option value="<%=request.getAttribute("location")%>><%=request.getAttribute("location")%></Option>
  65.         <Option value="Chandigarh">Chandigarh</Option>
  66.         <Option value="Pune">Pune</Option>
  67.         <Option value="Banglore">Banglore</Option>
  68.         </select>
  69.         </td>
  70.         </tr>
  71.  
  72.            <tr>
  73.            <td align="left"><font size=5>Role</font></td>
  74.            <%try{%>
  75.            <TD>
  76.             <select name="erRoles" id="erRoles"> 
  77.             <option>- - - - - - -</option>
  78.             <%for(int i=0;i<al.size();i++){%>
  79.             <Option value="<%=al.get(i).toString()%>"><%=al.get(i).toString()%></Option>
  80.             <%}%>
  81.             </select>
  82.             </TD>        
  83.             <%}
  84.             catch(Exception e)
  85.             {
  86.               e.printStackTrace();
  87.              }%>
  88.             </tr> 
  89.  
  90.             <tr>
  91.             <td align="right"><input type=submit name=action value="Submit" onclick="submitForm2();"></td>
  92.             <td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=reset name=action value="Reset"></td>
  93.             </tr>
  94.         </table>
  95.  
  96.     </form>
  97. </center>
  98. </body>
  99. </html>
In IE 6
In submitForm1() if I use alert before document.forms[0].action="SearchRecords"; then it only shows the alert box but do not submit the form to SearchRecords servlet and if i use it after document.forms[0].action="SearchRecords"; it neither shows alert box now submits the form to SearchRecords servlet.
Oct 30 '07 #15

acoder
Expert Mod 15k+
P: 16,027
Hi,
Thax for ur consideration. but I think the code in original post is sufficient to find the error.
No it wasn't. I've spotted the error by looking at your full code.

You've named your submit button "action" which is causing problems when setting the action property. Rename it to something else, even 'action1' will do.
Oct 30 '07 #16

P: 41
No it wasn't. I've spotted the error by looking at your full code.

You've named your submit button "action" which is causing problems when setting the action property. Rename it to something else, even 'action1' will do.
Hi,

The same situation even after changing the name of button.
When I change the dropdown list value the page shows an error on left bottom side of Browser and shows that "Object doesn't support this property or method" for document.forms[0].action="SearchRecords".

Thanks
Oct 31 '07 #17

P: 41
Hi,
The following code works properly
Expand|Select|Wrap|Line Numbers
  1. <%@ page import="javax.servlet.*"%>
  2. <%@ page import="javax.servlet.http.*"%>
  3.  
  4. <html>
  5. <head>
  6. <title> Form </title>
  7. <script language="javascript" type="text/javascript">
  8.  
  9. function submitForm1()
  10. {
  11.  
  12.    document.forms[0].action="SearchRecords";
  13.    alert("hjgjh");
  14.  
  15.    document.forms[0].submit();
  16. }
  17. </script>
  18.  
  19. </head>
  20.  
  21.  
  22.  
  23. <body bgcolor="fuschia">
  24. <center>
  25.  
  26.     <font size=7 color="red"> Please Enter the following information: </font>
  27.        <form name="form1" method="POST">
  28.            <table cellspacing="2" cellpadding="2" border="0">            
  29.         <tr>
  30.         <td align="left"><font size=5>Location</font></td>
  31.         <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  32.         <select name="l" onchange="submitForm1();">
  33.         <Option value="Chandigarh" selected="selected">Chandigarh</Option>
  34.         <Option value="Pune">Pune</Option>
  35.         <Option value="Banglore">Banglore</Option>
  36.         </select>
  37.         </td>
  38.         </tr>
  39.         </table>
  40.  
  41.     </form>
  42. </center>
  43. </body>
  44. </html>
Then why the code posted before doesn't work in IE.
Please reply it is really urgent and important.
Thanx
Oct 31 '07 #18

acoder
Expert Mod 15k+
P: 16,027
Then why the code posted before doesn't work in IE.
Now you don't have that submit button named "action" anymore, so it doesn't 'think' that the action object is being set to "SearchRecords" anymore.
Oct 31 '07 #19

P: 41
Now you don't have that submit button named "action" anymore, so it doesn't 'think' that the action object is being set to "SearchRecords" anymore.
Hi,
I just want to call the submitForm1() function on onchange event of location dropdown and want to submit the form to SearchRecords in the code below:(Please see the bold part in code)
[HTML]<%@ page import="java.util.ArrayList"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>

<html>
<head>
<title> Form </title>
<script language="javascript" type="text/javascript">

function submitForm1()
{

document.forms[0].action="SearchRecords";
alert("fghfhfhf");

document.forms[0].submit();
}

function submitForm2()
{
document.forms[0].action="Search";
document.forms[0].submit();
}
</script>

<%
ArrayList al=(ArrayList)session.getAttribute("str_");
%>


</head>



<body bgcolor="fuschia">



<center>

<font size=7 color="red"> Please Enter the following information: </font>
<form name="form1" method="POST">

<table cellspacing="2" cellpadding="2" border="0">
<tr>
<td><input type="hidden" name="role" id="role"></td>
</tr>

<tr>
<td align="left"><font size=5>Last Name</font></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=text name="sn" value="<%=request.getAttribute("lname") %>"></td>
</tr>

<tr>
<td align="left"><font size=5>FullName</font></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=text name="cn" value="<%=request.getAttribute("fname")%>"><td>
</tr>

<tr>
<td align="left"><font size=5>Location</font></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="l" onchange="submitForm1();">
<%if(request.getAttribute("location")!=null)%>
<Option value="<%=request.getAttribute("location")%>><%=re quest.getAttribute("location")%></Option>
<Option value="Chandigarh">Chandigarh</Option>
<Option value="Pune">Pune</Option>
<Option value="Banglore">Banglore</Option>
</select>
</td>
</tr>

<tr>
<td align="left"><font size=5>Role</font></td>
<%try{%>
<TD>
<select name="erRoles" id="erRoles">
<option>- - - - - - -</option>
<%for(int i=0;i<al.size();i++){%>
<Option value="<%=al.get(i).toString()%>"><%=al.get(i).toS tring()%></Option>
<%}%>
</select>
</TD>
<%}
catch(Exception e)
{
e.printStackTrace();
}%>
</tr>

<tr>
<td align="right"><input type=submit name=action value="Submit" onclick="submitForm2();"></td>
<td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;< input type=reset name="submitButton" value="Reset"></td>
</tr>
</table>

</form>
</center>
</body>
</html>[/HTML]

But it warks fine in Firefox and not in IE.if I use alert after document.forms[0].action="SearchRecords"; it shows neither alert nor submits the form and if i use alert before document.forms[0].action="SearchRecords"; it shows alert box but don't submit the form. It also shows a Browser warning on bottom left corner Object doesn't support Line 13(i.e.document.forms[0].action="SearchRecords";)

Thanks
Oct 31 '07 #20

acoder
Expert Mod 15k+
P: 16,027
As I told you before, you have to change the name of the submit button. IE is very easily confused!

On line 89, you have:[HTML]<input type=submit name=action value="Submit" onclick="submitForm2();">[/HTML] Change "action" to "action1" or some other name that is not the name of a method or attribute.
Oct 31 '07 #21

P: 41
As I told you before, you have to change the name of the submit button. IE is very easily confused!

On line 89, you have:[HTML]<input type=submit name=action value="Submit" onclick="submitForm2();">[/HTML] Change "action" to "action1" or some other name that is not the name of a method or attribute.
Hi,
I have tried it but still its not working

Thanks
Oct 31 '07 #22

acoder
Expert Mod 15k+
P: 16,027
Hi,
I have tried it but still its not working

Thanks
So what happens now? Any errors? Can you also post your revised code?
Oct 31 '07 #23

P: 41
So what happens now? Any errors? Can you also post your revised code?
Hi,

Revised code as below

Expand|Select|Wrap|Line Numbers
  1. <%@ page import="java.util.ArrayList"%>
  2. <%@ page import="javax.servlet.*"%>
  3. <%@ page import="javax.servlet.http.*"%>
  4.  
  5. <html>
  6. <head>
  7. <title> Form </title>
  8. <script language="javascript" type="text/javascript">
  9.  
  10. function submitForm1()
  11. {
  12.  
  13.    document.forms[0].action="SearchRecords";
  14.    alert("fghfhfhf");
  15.  
  16.    document.forms[0].submit();
  17. function submitForm2()
  18. {
  19. document.forms[0].action="Search";
  20. document.forms[0].submit();
  21. }
  22. </script>
  23.  
  24. <%
  25. ArrayList al=(ArrayList)session.getAttribute("str_");
  26. %>
  27.  
  28.  
  29. </head>
  30.  
  31.  
  32.  
  33. <body bgcolor="fuschia">
  34.  
  35.  
  36.  
  37. <center>
  38.  
  39.     <font size=7 color="red"> Please Enter the following information: </font>
  40.        <form name="form1" method="POST">
  41.  
  42.            <table cellspacing="2" cellpadding="2" border="0">
  43.             <tr>
  44.         <td><input type="hidden" name="role" id="role"></td>
  45.             </tr>
  46.  
  47.         <tr>
  48.         <td align="left"><font size=5>Last Name</font></td>
  49.         <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=text name="sn" value="<%=request.getAttribute("lname") %>"></td>
  50.         </tr>
  51.  
  52.         <tr>
  53.         <td align="left"><font size=5>FullName</font></td>
  54.         <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=text name="cn" value="<%=request.getAttribute("fname")%>"><td>
  55.         </tr>
  56.  
  57.         <tr>
  58.         <td align="left"><font size=5>Location</font></td>
  59.         <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  60.         <select name="l" onchange="submitForm1();">
  61.         <%if(request.getAttribute("location")!=null)%>
  62.         <Option value="<%=request.getAttribute("location")%>><%=request.getAttribute("location")%></Option>
  63.         <Option value="Chandigarh">Chandigarh</Option>
  64.         <Option value="Pune">Pune</Option>
  65.         <Option value="Banglore">Banglore</Option>
  66.         </select>        </td>
  67.         </tr>
  68.  
  69.         <tr>
  70.         <td align="left"><font size=5>Role</font></td>
  71.         <%try{%>
  72.         <TD>
  73.             <select name="erRoles" id="erRoles"> 
  74.             <option>- - - - - - -</option>
  75.             <%for(int i=0;i<al.size();i++){%>
  76.             <Option value="<%=al.get(i).toString()%>"><%=al.get(i).toString()%></Option>
  77.             <%}%>
  78.             </select>
  79.             </TD>      
  80.             <%}
  81.             catch(Exception e)
  82.             {
  83.               e.printStackTrace();
  84.              }%>
  85.             </tr> 
  86.  
  87.             <tr>
  88.             <td align="right"><input type=submit name=action value="Submit" onclick="submitForm2();"></td>
  89.             <td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=reset name="submitButton" value="Reset"></td>
  90.             </tr>
  91.         </table>
  92.  
  93.     </form>
  94. </center>
  95. </body>
  96. </html>
The same situation ie when i use alert box before setting document.forms[0].action="SearchRecords" it shows the alert bax on onchange event but don't submit the code but when i place alert before document.forms[0].action="SearchRecords" neither it shows alert box nor it submits the form.

Even in both the cases it shows a warning (that browser shows when page loads) and the details are

Line: 12
Char: 4
Error: Object doesn't support this property or Method
Code: 0
URL: ...........................


Thanks
Oct 31 '07 #24

acoder
Expert Mod 15k+
P: 16,027
You've not actually made the change.

Change line 89 to:
[HTML]<td align="right"><input type=submit name="action1" value="Submit" onclick="submitForm2();"></td>[/HTML]
Oct 31 '07 #25

P: 41
You've not actually made the change.

Change line 89 to:
[HTML]<td align="right"><input type=submit name="action1" value="Submit" onclick="submitForm2();"></td>[/HTML]
Hi,
Sorry, actually i have changed the one button code and not the other now this is working fine.

But still I am not clear why the same (wrong) code was working fine on Firefox.
Can you tell me the reason or some link where i can find out these differences between firefox and IE.
Thanks
Thanks a lot
Oct 31 '07 #26

acoder
Expert Mod 15k+
P: 16,027
The situation is same as described in above post.
Now you've renamed the reset button to "action". Use a different name.
Oct 31 '07 #27

Post your reply

Sign in to post your reply or Sign up for a free account.