PDA

View Full Version : Form with Javascript validation needs help



mrcasc
Feb 9th, 2011, 02:30 AM
I have a form developed in Dreamweaver CS5 using Spry Assets, I have 2 required fields in the form. One is email the other is phone. I want the user to only have to fill in one or the other, but one or the other needs to be filled out.

Here is the form code:

[code]<form id="form1" name="form1" method="post" action="http://www.greenhousegraphix.com/GatewayVentures/sendmail.php">
<span id="sprytextfield1"><label>Name</label>
<input name="Name" type="text" id="Name" size="45" />
<span class="textfieldRequiredMsg">A value is required.</span></span><br />
<span id="sprytextfield3"><label>Title</label>
<input name="Title" type="text" id="Title" size="45" />
</span><br />
<span id="sprytextfield2"><label>Company</label>
<input name="Company" type="text" id="Company" size="45" />
</span><br />
<span id="sprytextarea1"><label>Address</label>
<textarea name="Address" id="Address" cols="39" rows="2"></textarea>
</span><br />
<span id="sprytextfield4"><label>City</label>
<input name="City" type="text" id="City" size="45" />
</span><br />
<span id="sprytextfield5"><label>State</label>
<input name="State" type="text" id="State" size="45" />
</span><br />
<span id="sprytextfield6"><label>Zip</label>
<input name="Zip" type="text" id="Zip" size="45" />
<span class="textfieldInvalidFormatMsg">Invalid format.</span><span class="textfieldMinCharsMsg">Minimum number of characters not met.</span><span class="textfieldMinValueMsg">The entered value is less than the minimum required.</span></span><br />
<span id="sprytextfield7"><label>Phone</label>
<input name="Phone" type="text" id="Phone" size="45" />
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><br />
<span id="sprytextfield8"><label>Email</label>
<input name="Email" type="text" id="Email" size="45" />
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><br />
<span id="sprytextarea2"><label>Message</label>
<textarea name="Message" id="Message" cols="39" rows="6"></textarea>
</span><br />


<input name="SUBMIT" type="image" class="marginleft95px" src="images/submit.jpg" />
</form>
</div>
<div id="apDiv2"><img src="images/contact-us-keyboard.jpg" width="318" height="230" alt="contact us" /></div>
<div id="apDiv3"><img src="images/contact-us.jpg" width="318" height="230" alt="contact us" /></div>
</div></div>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {validateOn:["blur"]});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "none", {isRequired:false});
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "none", {isRequired:false});
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "none", {isRequired:false});
var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5", "none", {isRequired:false});
var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6", "zip_code", {isRequired:false});
var sprytextfield7 = new Spry.Widget.ValidationTextField("sprytextfield7", "phone_number", {validateOn:["blur"], hint:"(999) 999-9999"});
var sprytextfield8 = new Spry.Widget.ValidationTextField("sprytextfield8", "email", {validateOn:["blur"]});
var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1", {isRequired:false});
var sprytextarea2 = new Spry.Widget.ValidationTextarea("sprytextarea2", {isRequired:false});
</script>[code]



Please help!!

oVTech
Feb 9th, 2011, 08:56 AM
We do not have the code so we can help you. What you have posted above is just a reference to the long, long, long, long, very long code in some file in your main folder. Even if you could provide us with that file, which I don't recommend because it's way too long, I doubt that anyone will offer to take a look at it. The answer is.... Do not use DW! Why? Because it produces bloated and insufficient code. And please do not write back and try to stand up for it and tell me how great DW is for designers, artists, UI developers etc. If you really want a small and efficient form validation script, just search this forum and you'll find many examples.

Philip M
Feb 9th, 2011, 09:21 AM
We do not have the code so we can help you. What you have posted above is just a reference to the long, long, long, long, very long code in some file in your main folder. Even if you could provide us with that file, which I don't recommend because it's way too long, I doubt that anyone will offer to take a look at it. The answer is.... Do not use DW! Why? Because it produces bloated and insufficient code. And please do not write back and try to stand up for it and tell me how great DW is for designers, artists, UI developers etc. If you really want a small and efficient form validation script, just search this forum and you'll find many examples.

Seconded! :thumbsup:


I want the user to only have to fill in one or the other,
Why?