Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > HTML, XHTML and CSS

Reply
 
LinkBack Thread Tools
Old June 10th, 2009, 07:04 AM   #1
New Member
 

Join Date: May 2009
Location: uk
Age: 37
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 speed is on a distinguished road
Validate form code needed

I'm struggling to get my code right in order to validate a form. I have a checkbox which when checked accepts terms and conditions, i don't want the form to be able to be submitted without the button being checked. If i put a link to the page and include the code could someone please tell me exaclty what code i have to have and where. Thanks

http://www.elitetradesmen.com/searchtrades1.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title>Elite Tradesmen of Southport &amp; surrounding areas</title>
<link rel="stylesheet" href="style.css" type="text/css" charset="utf-8" />

</head>
<body>
<div id="wrapper">
<h1>Elite tradesmen</h1>
<div id="nav">
<a href="index.html">Home</a>
<a href="searchtrades1.html" class="selected">Submit Work</a>
<a href="policies2.html">Our Policies</a>
<a href="areas1.html">Areas</a>
<a href="contact2.html">Contact Us</a>
</div>
<div id="body">
<div id="body-top">
<div id="body-top-2"></div>
<div id="body-bot">
<div id="welcome">
<img src="images/pic_1.jpg" width="231" height="301" alt="Pic 1" />
<h2>Submit your job</h2>
<p>We will always post all received jobs on the website within 24 hours. If you would like someone to visit you in person to take details of the work please use the form on this page.</p>
<p>&nbsp;</p>
<p>Please read our policies page for payment terms, service agreements etc.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;<img src="images/logo12.jpg" alt="" width="178" height="138" /></p>
</div>
<div id="content">
<img src="images/page images/submit.jpg" width="109" height="109" alt="Pic 2" class="left" />
<h2>Submit your work here</h2>
<p>To request quotes from our tradesmen simply fill in the form below.</p>
<p>Your job will then be posted on our site and alerts sent to all tradesmen in the service concerned.</p>
<p>Quotes will be sent to you as and when we receive them. You will be sent portfolio information for each tradesman with every quote received.</p>
<p>When you have decided which tradesmen to use we will draw up a plan of works which will detail work to be completed, agreed amount, date to commence and complete work. This plan of works will be signed by both customer and tradesman. At this time 10% of the total quote will be paid to Elite Tradesmen by the customer.</p>
<p>When the work is completed the customer will sign the plan of work to confirm that the work has been completed to your satisfaction. Once the work has been signed off payment will be made in full from the customer to the tradesman.</p>
<p>At this point we ask that you leave us some feedback in relation to the service you received both from us and your tradesman.</p>
<p>&nbsp;</p>
<p>To submit your job please complete this form:</p>
<p>&nbsp;</p>
<p>Name:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<elephone>
Telephone:<br />
<input type="text" name="FirstName" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="LastName" />
<br />
</p>
<p>Email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Prefered contact method:<br />
<input type="text" name="Tel" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; &nbsp;&nbsp;&nbsp;
<input type="text" name="EmailFrom" />
<br />
</p>
<p>Address:<br />
<textarea name="Basicjobdetails" cols="35" rows="5"></textarea>
</p>
<p>Trade required:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;<br />
<input type="text" name="trade" id="trade">
&nbsp;<br />
</p>
<p>Preferred start date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Preferr ed completion date:<br />
<input type="text" name="Tel2" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; &nbsp;&nbsp;&nbsp;
<input type="text" name="EmailFrom2" />
<br />
</p>
<p>Details of the work you would like completed :<br />
<textarea name="Basicjobdetails2" cols="35" rows="5"></textarea>
</p>
<div align="justify">
<input type="radio" onclick="check(this)" name="agree">
I agree to all the terms and conditions shown under 'Our Policies' </div>
<p>
<input type="submit" name="submit2" value="Submit" />
</p>
<div class="fineline"></div>
<p>&nbsp; </p>
</div>
<div class="clear"></div>
</div>
</div>
</div>
<div id="footer">
<p>Copyright © 2009, Elite Tradesmen. All rights reserved</p>
</div>
</div>

</body>
</html>
speed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old June 10th, 2009, 12:53 PM   #2
Reputable Member
 

Join Date: Nov 2008
Location: Lexington, KY
Posts: 243
Thanks: 0
Thanked 1 Time in 1 Post
Rep Altering Power: 0 Dubbs is on a distinguished road
Re: Validate form code needed

I will let you do all the formatting so that you can make it fit your theme. Also, you may want to change the name of the forms, since I use generic ones.

Add this into the head of your HTML document.
Code:
<script language="Javascript" type="text/JavaScript">  
 function check(){  
  if (document.agreement_form.agreed.checked==''){  
   document.agreement_form.submit_button.disabled=true  
  }else{  
   document.agreement_form.submit_button.disabled=false  
  }  
 }  
</script>
Let me break down the JavaScript really quick. Maybe it will help you understand it a little more.

This code
Code:
if (document.agreement_form.agreed.checked=='')
Is checking to see if the element named agreed inside the element named agreement_form is checked. So if you wanted, you can change the form (agreement_form) to anything you want, and you can change the part you want the user to click (agreed) to what ever you want.

Hopefully that makes the process a little clearer. Just remember that the document is the current page. Everything after that is element names until the part after the last period. That is the attribute we going to check for. So if we wanted we could go five elements deep into the document as long as we know the element names.

The same thing goes for the submit button.
Code:
   document.agreement_form.submit_button.disabled=false
The difference here is that we are using JavaScript to change the value of disabled attribute. By default it is set to disabled (or true) in the HTML code. So the if statement (listed above) checks to see if the element we are verifying is "active" or true. If so then we change the value of disable to false, or enable the button.

And this is the form that you can use.
Code:
<form name="agreement_form">
Name: <input type="text" name="Name" /><br />
Telephone: <input type="text" name="Tel" /><br />
Email: <input type="text" name="email" /><br />
Address: <input type="text" name="address" /><br />
Trade Required: <input type="text" name="trade" /><br />
Start Date: <input type="text" name="start_date" /><br />
End Date: <input type="text" name="end_date" /><br />
Work Needed <input type="text" name="work" /><br />
<input type="radio" onchange="check()" name="agreed"> I agree to all the terms and conditions shown under 'Our Policies'<br />
<input type="submit" disabled name="submit_button">
</form>
To make the code work we use a JavaScript event so that if the status of the element changes (in this case clicked) we run the function check. (Note, you can use onclick in this example, but onchange is more appropriate in this case sense we are checking the status of the element.)
Dubbs is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old June 11th, 2009, 06:31 AM   #3
New Member
 

Join Date: May 2009
Location: uk
Age: 37
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 speed is on a distinguished road
Re: Validate form code needed

Thanks. I just wish i'd checked back on this forum before now, your reply would have saved me so much time. At least now after hours of research and writing the code i understand forms a bit more now.
speed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old June 12th, 2009, 10:39 AM   #4
Reputable Member
 

Join Date: Nov 2008
Location: Lexington, KY
Posts: 243
Thanks: 0
Thanked 1 Time in 1 Post
Rep Altering Power: 0 Dubbs is on a distinguished road
Re: Validate form code needed

Speed, if you read the post for you other question you asked about forms, and use the information here and what you learned, you should be able to set up a script to send you emails really soon.
Dubbs is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Validate Radio Buttons in Existing Code dawgmom JavaScript 6 June 3rd, 2008 08:20 PM
Validate a form only if certain conditions are met svennie12 JavaScript 2 May 10th, 2008 11:59 AM
[SOLVED] Validate Form Class soloam JavaScript 2 November 28th, 2007 11:51 AM
validate form Monie Classic ASP 1 September 2nd, 2004 06:06 AM
validate form? Nick JavaScript 10 August 31st, 2004 04:47 AM


Search Engine Optimization by vBSEO 3.2.0 RC8