473,766 Members | 2,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript won't work in IE7

6 New Member
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="#99000 0"><span class="style1"> <font color="#FFFFFF" face="Arial, Helvetica, sans-serif"><strong> Answer</strong></font></span></td>
<td width="299" rowspan="2" valign="top"><l abel>
<input name="Answer" type="text" id="Answer" size="34" />
</label></td>
</tr>
<tr>
<td height="39" colspan="2">
<div align="left"><l abel>
<input type="submit" name="Submit" value="Submit" onClick="checkA nswer(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 1541
mplungjan
13 New Member
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="retur n checkAnswer(thi s)">
.
.
<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
neoseeker191
6 New Member
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
mplungjan
13 New Member
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
3643
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 there is a " or ' in the character string. <SCRIPT language=JavaScript> function Add_Term(SearchTerm) { window.opener.document.advsearch.name_title.value += SearchTerm; window.close();
6
10387
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 some-processing when the control is clicked. In other words, it has to generate a postback. I'd like to use a <asp:LinkButton> to do this control because it looks like a text hyperlink and it generates postback for server-side processing. However, I...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.