473,395 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Javascript won't work in IE7

It works fine in Firefox 2+ but in IE7 the alert window doesnt appear and the script doesnt work.

Maybe I'm missing something

Heres the form the script is tied to:


[HTML] <form id="Quiz" name="Quiz" method="get" >
<table width="405" table="table" height="24" border="0" align="center">
<!--DWLayoutTable-->
<tr>
<td width="96" valign="top" bgcolor="#990000"><span class="style1"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif"><strong>Answer</strong></font></span></td>
<td width="299" rowspan="2" valign="top"><label>
<input name="Answer" type="text" id="Answer" size="34" />
</label></td>
</tr>
<tr>
<td height="39" colspan="2">
<div align="left"><label>
<input type="submit" name="Submit" value="Submit" onClick="checkAnswer(this.form)" />
</label>
</div></td>
</tr>
</table>
</form>[/HTML]


Heres the script, its an external script preloaded in the head section:

Expand|Select|Wrap|Line Numbers
  1. function checkAnswer (form)
  2. {
  3.     var Answer = form.Answer.value;
  4.     if (Answer == "clarkston park")
  5.     {
  6.     alert ("!!!! Yes you are Correct !!!!  ... Your gift will be there from 12:45pm - 1:15pm")
  7.     }
  8.     else if (Answer == "Clarkston Park")
  9.     {
  10.     alert ("!!!! You are Correct !!!!  ... Your gift will be there from 12:45pm - 1:15pm");
  11.     location = "http://someplace.com";
  12.     }
  13.     else
  14.     {
  15.     alert ("You are Incorrect. Please try again. **Hint: C.P.**")
  16.     }
  17. }
Dec 25 '07 #1
3 1503
A few things are going on here

1. Never use onClick of a submit button - instead use the onSubmit of the form and return false if the form itself should not be submitted.

2. You should not rely on javascript to hide an answer to a password-like question.

3. Your script can be simpler:

[HTML] <form id="Quiz" name="Quiz" method="get"
onSubmit="return checkAnswer(this)">
.
.
<input type="submit" name="Submit" value="Submit" />
</form>[/HTML]

Expand|Select|Wrap|Line Numbers
  1. function checkAnswer (form) {
  2.   var answer = form.Answer.value;
  3.   if (answer!="") answer=answer.toLowerCase();
  4.   if (answer == "clarkston park")  {
  5.     alert ("!!!! Yes you are Correct !!!!  ... Your gift will be there from 12:45pm - 1:15pm")
  6.      location = "http://someplace.com";
  7.   }
  8.   else {
  9.     alert ("You are Incorrect. Please try again. **Hint: C.P.**")
  10.   }
  11.   return false; // cancel the form
  12. }
Dec 25 '07 #2
Changing it to onSubmit results in the script not working at all in Firefox or IE. The other changes still aren't making it work, unfortunately.

I appreciate the help.
Dec 25 '07 #3
I believe you may have pasted the script incorrectly or missed something in the html you gave me.
Here is the script combined with your code and it works as intended in IE, Firefox and Safari on Windows XP
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script>
  4. function checkAnswer (form) {
  5.   var answer = form.Answer.value;
  6.   if (answer!="") answer=answer.toLowerCase();
  7.   if (answer == "clarkston park")  {
  8.     alert ("!!!! Yes you are Correct !!!!  ... Your gift will be there from 12:45pm - 1:15pm")
  9.     location = "http://www.google.com/search?q=clarkston+park";
  10.   }
  11.   else {
  12.     alert ("You are Incorrect. Please try again. **Hint: C.P.**")
  13.   }
  14.   return false; // cancel the form
  15. }
  16. </script>
  17. </head>
  18. <body>
  19. <form id="Quiz" name="Quiz" method="get" onSubmit="return checkAnswer(this)">
  20. <table width="405" table="table" height="24" border="0" align="center">
  21.               <!--DWLayoutTable-->
  22.               <tr>
  23.                 <td width="96" valign="top" bgcolor="#990000"><span class="style1"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif"><strong>Answer</strong></font></span></td>
  24.                 <td width="299" rowspan="2" valign="top"><label>
  25.                   <input name="Answer" type="text" id="Answer" size="34" />
  26.                 </label></td>
  27.               </tr>
  28.               <tr>
  29.                 <td height="39" colspan="2">
  30.                     <div align="left"><label>
  31.                       <input type="submit" name="Submit" value="Submit" />
  32.                       </label>
  33.                   </div></td>
  34.               </tr>
  35.             </table>
  36.           </form>
  37. </body>
  38. </html>          
  39.  
Dec 26 '07 #4

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

Similar topics

3
by: NecroJoe | last post by:
I am using PHP to generate a little javascript for one of my pages. In short it allows a user to select a value from a list and pop it into a form field on a seperate page. This works well unless...
6
by: domtam | last post by:
First of all, my ASP.NET application has to support browser with Javascript disabled. In the application There is a control that looks like a text hyperlink, but the server-side has to do...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.