473,394 Members | 1,870 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,394 software developers and data experts.

Too many alert messages

15
Hi

Can anyone give advice on how to get only one alert message out of this code:

Im hoping its an easy solution but Im stuck on it & only new to JavaScript.

Many thanks

M

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <head>
  4. <title>Form</title>
  5.  
  6. <script language="JavaScript" type="text/JavaScript">
  7.  
  8. function validateForm(){
  9.     var isChecked = window.document.fmOrder.usedSearch.checked;
  10.  
  11.     if (isChecked == true){
  12.         for(j=0; j<4; j++)
  13.         if (!(document.fmOrder.whichSearch[j].checked == true)){
  14.             alert("Which search engine did you use?");
  15.         }
  16.     } 
  17. }
  18.  
  19. </script>
  20. </head>
  21.  
  22. <body>
  23. <form id="fmOrder" name="fmOrder" method="get" action="FormProcessor.html" onsubmit="return validateForm(this);">
  24.  
  25. <table>
  26.  <tr>
  27.      <td> Did you use a search engine to find us?</td>
  28.     <td colspan="2" nowrap="nowrap"><input name="usedSearch" type="checkbox" id="usedSearch" value="Yes" />
  29.     </tr>
  30. </table> 
  31. <br>
  32. <br>
  33. <table>
  34.     <tr>
  35.     <td colspan="2" align="right" valign="top" bgcolor="#F0F0F0" class="borderBR">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If yes, please let us know which one: </td>
  36.     <td colspan="2" valign="top" bgcolor="#F0F0F0"><input name="whichSearch" type="radio" id="whichSearch" value="Google" />Google<br />
  37.       <input name="whichSearch" type="radio" value="Yahoo!" />Yahoo!<br />
  38.       <input name="whichSearch" type="radio" value="Lycos" />Lycos<br />
  39.       <input name="whichSearch" type="radio" value="Other" />Other </td>
  40.     </tr>
  41. </table>
  42. <br>
  43. <br>
  44.  
  45. <input type="submit" name="Submit" value="Submit Order" />
  46.  
  47. </form>
  48. </body>
  49. </html>
  50.  
  51.  
Aug 20 '07 #1
3 1568
gits
5,390 Expert Mod 4TB
hi ...

you may break the loop when you have an alert ... so put a

Expand|Select|Wrap|Line Numbers
  1. break;
  2.  
after the alert-statement (line13)

kind regards
Aug 20 '07 #2
MKO
15
Cheers

Now I only get one message, however it still appears even if the last one is selected.

Do I have to ditch the loop and go for an "if / else if / else if / else" statement?

What will give the best result?
Aug 20 '07 #3
gits
5,390 Expert Mod 4TB
heya ....

sorry i overlooked that ;)

use the following:

Expand|Select|Wrap|Line Numbers
  1. var show_alert = true;
  2.  
  3. for(j = 0; j < 4; j++) {
  4.     if (document.fmOrder.whichSearch[j].checked == true) {
  5.         show_alert = false;
  6.         break;
  7.     }
  8. }
  9.  
  10. if (show_alert) {
  11.     alert("Which search engine did you use?");
  12. }
kind regards
Aug 20 '07 #4

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

Similar topics

9
by: Justin Koivisto | last post by:
Is there a way to create an alert-like message box that uses a custom image? Basically, I want to replace the default ! image with something else. -- Justin Koivisto - spam@koivi.com PHP...
8
by: Dan Williams | last post by:
We have an employee table that contains bank details and are experiencing problems with account numbers being erased and lost. In order to track down why this is happening (either due to our...
3
by: dgmoore | last post by:
Hello - I'm having trouble with JavaScript alerts in an imagemap. The mapped areas are cells in a table, and the alerts display info related to the cell that is clicked. The problem is that,...
11
by: Alistair Saldanha | last post by:
I'm looking for the event that is fired by Internet Explorer to an "alert": <SCRIPT> Alert("You already have a session open") </SCRIPT> The event would be webBrowser.Document.???? Much...
6
by: bonehead | last post by:
Greetings, I'm working on an e-mail form (btw many thanks to Philip Ronan for the very cool email address format tester function, best I've seen so far). I've been trying, with limited...
4
by: Robert Zurer | last post by:
When I click a Button server control I want two things to happen. The server returns a string array of error messages. A Javascript alert appears showing the errors. I can do this using the...
4
by: Gregc. | last post by:
Hi Would someone have a basic example of form validation that validates name and address, but using only one alert box that displays which fields haven't been completed? I can do it on an...
3
by: Wayne Deleersnyder | last post by:
Hi All, I'm trying to create a function that will cause a pop-up alert to appear if dates which were chosen from a drop-down list were invalid on a page. There's 4 dates, so there's the...
1
by: sivaprasadch | last post by:
please can any one suggest me to how to display the alert message text in the different languages. iam implementing localization and globalization concept in my application ,when i change the...
23
by: Marge | last post by:
This may be in the wrong forum, but here goes. How can I display an alert in the users browser window from an asp page. For example, a welcome message. I know I can do this with response.write,...
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...
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
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,...
0
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...
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.