473,769 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

form mandatory fields

57 New Member
Ive been looking through a whole tonne of sites to try to find out how I can make my fields mandatory but havnt been able to find something so far which actually tells me whwta I want to know. Ive tried a couple of code segments but they havnt been working. can anyone tell me how I can make fields in my code mandatory?

My attempt at solving this is below:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <title>Coals Spiral Brochure Enquiry Form</title>
  5.  
  6. <meta name="description" content="">
  7.  
  8. <meta name="keywords" content="">
  9. <script language="javascript" 
  10.   type="text/javascript">
  11.  
  12. function validateForm(brochure1)
  13. {
  14.  
  15. if(""==document.forms.brochure1.firstname.value)
  16. {
  17. alert("Please enter your first name.");
  18. return false;
  19. }
  20.  
  21. if(""==document.forms.brochure1.lastname.value)
  22. {
  23. alert("Please enter your last name.");
  24. return false;
  25. }
  26.  
  27. if(""==document.forms.brochure1.email.value)
  28. {
  29. alert("Please enter your email address.");
  30. return false;
  31. }
  32.  
  33. }
  34. if(""==document.forms.brochure1.phone.value)
  35. {
  36. alert("Please enter your Phone number.");
  37. return false;
  38. }
  39.  
  40. }
  41.  
  42. if(""==document.forms.brochure1.country.value)
  43. {
  44. alert("Please enter your country.");
  45. return false;
  46. }
  47.  
  48. }
  49.  
  50. </script>
  51. </head>
  52. <body bgcolor="white" text="black">
  53.  
  54. <table width="60%" align="center">
  55. <tr>
  56. <td>
  57. <font face=Arial size=2>
  58.  
  59. <IMG SRC="http://www.mdmintec.reachpoint.com/Data/mdmintec/Roche%20MT%20sm.jpg" align="right">
  60. <strong><BR><BR><BR><BR><BR>
  61. Coals Spiral Brochure Enquiry Form</strong>
  62. <HR style="WIDTH: 100%; HEIGHT: 1px" align=center width="100%" color=black>
  63. <BR>
  64. Please fill out your details below in order to receive our Coals Spiral Brochure.
  65. <BR><BR>
  66.  
  67. <form method="post"  onsubmit='return validateForm()' action="http://svr86.ehostpros.com/~minera86/brochure1.php">
  68. <TABLE width=85% align=center cellSpacing=1 cellPadding=1 border=0>
  69. <TR>
  70. <TD>
  71. <font face=Arial size=2>First Name: 
  72. </TD>
  73. <TD>
  74. <INPUT title="Your Google Toolbar can fill this in for you. Select AutoFill" maxLength=100 size=40 name=firstname> 
  75. </TD>
  76. </TR>
  77. <TR>
  78. <TD>
  79. <font face=Arial size=2>Last Name: 
  80. </TD>
  81. <TD>
  82. <INPUT title="Your Google Toolbar can fill this in for you. Select AutoFill" maxLength=100 size=40 name=lastname> 
  83. </TD>
  84. </TR>
  85. <TR>
  86. <TD>
  87. <font face=Arial size=2>Email: 
  88. </TD>
  89. <TD>
  90. <INPUT title="Your Google Toolbar can fill this in for you. Select AutoFill" maxLength=100 size=40 name=email>
  91. </TD>
  92. </TR>
  93. <TR>
  94. <TD>
  95. <font face=Arial size=2>Phone: 
  96. </TD>
  97. <TD>
  98. <INPUT title="Your Google Toolbar can fill this in for you. Select AutoFill" maxLength=100 size=40 name=phone>
  99. </TD>
  100. </TR>
  101. <TR>
  102. <TD>
  103. <font face=Arial size=2>Country: <BR><BR><BR><BR>
  104. </TD>
  105. <TD>
  106. <INPUT title="Your Google Toolbar can fill this in for you. Select AutoFill" maxLength=100 size=40 name=country>
  107. <p Align=right>
  108. <input class="BButton" value="Send" name="cmdSubmit" type="submit">
  109. </align>
  110. </TD>
  111. </TR>
  112. </TABLE>
  113. </form>
  114.  
  115.  
  116. </font>
  117. </body>
  118. </html>
  119.  
  120.  
Oct 29 '07 #1
6 1732
Dameon99
57 New Member
btw this code worked for another site.. but for some reason not this one. Can anyone tell me what Im doing wrong?!
Oct 29 '07 #2
dmjpro
2,476 Top Contributor
btw this code worked for another site.. but for some reason not this one. Can anyone tell me what Im doing wrong?!
What is "brochure1" in "document.forms .brochure1.firs tname.value" expression?

Debasis
Oct 29 '07 #3
Dameon99
57 New Member
What is "brochure1" in "document.forms .brochure1.firs tname.value" expression?

Debasis
"brochure1" is name of the html file brochure1.html.
Oct 29 '07 #4
dmjpro
2,476 Top Contributor
"brochure1" is name of the html file brochure1.html.
all these expression "document.forms .brochure1" should be changed into "document.f orms[0]"

Debasis
Oct 29 '07 #5
Dameon99
57 New Member
all these expression "document.forms .brochure1" should be changed into "document.f orms[0]"

Debasis

Why is this? JUst wondering if you could explain it s I understand what I am doing wrong.
Oct 29 '07 #6
acoder
16,027 Recognized Expert Moderator MVP
Why is this? JUst wondering if you could explain it s I understand what I am doing wrong.
You can't use "brochure1" because it doesn't refer to the form.

forms[0] is the first form on the page. If you could possibly have more than one form, you would be better off giving your form an id and using document.getEle mentById(form-id).
Oct 29 '07 #7

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

Similar topics

6
1388
by: MAFranklin | last post by:
I've created a form with several input fields. At the beginning of my form I use a set of radio buttons to determine how to validate the form as well as determine what fields are required. Because the form is so lengthy, I would like to aid users by including visual clues as to what fields require information by changing the background color of that field to red. I understand how to accomplish this field by field however, I am looking for...
1
2966
by: Jason | last post by:
I have a main form with a sub form. All the fields in the subform are mandatory. I had some code on the main form Before Update Event to check if all the fields in the sub form have data. If not, I want to cancel update event and allow user to enter the sub form to fill in all mandatory fields. I tried many code and don't have any solution to work around. It never allows me to go into the sub form again after triggering the before update...
5
2534
by: Olly | last post by:
Hello Everyone! Could someone please have a look at my JS Form I posted below....Something wrong there, but I don't understand what's exactly. Many thanks. Olly =============================== <script language="JavaScript">
2
4217
by: RajaKannan | last post by:
Hi All, I have a form in which i have few mandatory fields. Wheneve the user tries to save, i check for these fields and alert them, if thet are empty. I have a CLOSE button in my form and whenever the user clicks the CLOSE button, i ask the user whether he wants to save before closing the form. On the Form_Unload event, i check whether there are any new changes and if yes, i pompt the user for a save. But if they have not filled any of...
1
1552
by: AR123 | last post by:
Hi I have set up mandatory form fields but it dosne t seem to be working. Would appreciate it if somone could have a look. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Proforma</title> <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
4
2133
by: plumba | last post by:
Let me explain.... I have a form (most of which you guys have helped me with!!). The initial problem I was having is that it was holding the data in the fields after submit, I resolved this by putting the whole form in a set of <div> tags and the form now collapses after they click submit. Perfect!! But, have set some mandatory fields using java, and I need to it validate the these fields before it collapses the form - otherwise it says...
1
3371
by: AR123 | last post by:
The mandatory form field that is not working is the TYPE OF ILLUSTRATION. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Proforma</title> <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
5
2549
by: plumba | last post by:
Hi all I have a form (see below), which for some reason has decided to stop functioning all together. It just does not call up the function. It is called up in the opening <form> tag but fails.... Any ideas??? <html> <head><title>New Details</title> </head> <center> <H2><IMG SRC="$(path)smlogo.gif"><br>
2
1693
by: AR123 | last post by:
Hi I have set up a form. What I want to to is with the fields: Company Postcode Agency Number Policy Number I want these to be mandatory however if someone fills in the company postcode for example the other two fields dont need to be filled in. I just put a line of text in saying: Please ensure either Company Postcode, Agency Number or Policy Number is filled in. but this is not really working well as people are still leaving it blank...
0
9423
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
10212
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...
0
10047
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9995
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,...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
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.