Jump to content

Validating a form with JS turned off


Recommended Posts

Right now, my form uses a JavaScript file to validate responses. I am trying to prevent a form from being submitted when JavaScript is turned off. Thus, I want to create some simple logic in ASP that tells the user to enter their name when "Your Name" is given as a value (Note: by default, I have "Your Name" set as the value). Here is what my form looks like:<script language="JavaScript" src="form_check.js" type="text/javascript"></script><form class="fpq" action="price_quote.asp" method="POST" id="quotesform1" name="quotesform1" onSubmit="return checkquotevalues();"><input name="ReferralCode" type="hidden"><input type="text" name="NumberOfEmployees" id="NumberOfEmployees" value="# of Employees" tabindex="1" onfocus="if(this.value == '# of Employees') {this.value = '';}" onblur="if (this.value == '') {this.value = '# of Employees';}" /><br /><select name="PayrollFrequency" tabindex="2" /> <option value='0'>Select one</option> <option value="W">Weekly</option> <option value="BW">Bi-Weekly</option> <option value="S">Semi-Monthly</option> <option value="M">Monthly</option> </select><br /><input type="text" name="YourName" id="YourName" value="Your Name" tabindex="3" onfocus="if(this.value == 'Your Name') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Your Name';}" /><asp:RequiredFieldValidator id="valLastName" ControlToValidate="LastName" ErrorMessage="Please enter your name!" runat="server" /><br /><input type="text" name="Email" id="Email" value="Email" tabindex="4" onfocus="if(this.value == 'Email') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Email';}" /><br /><input type="text" name="PhoneNumber" id="PhoneNumber" value="Phone" tabindex="5" maxlength="14" onfocus="if(this.value == 'Phone') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Phone';}" /><input type="image" src="show-me.gif" alt="Show Me a Price Quote" id="Image1" name="submit2" tabindex="8" /><input type="hidden" name="ContactRegarding" value="Q"><input type="hidden" name="SaveData" value="True"><input type="hidden" name="ReferralCode" value="<% =fm_refcode%>"><input type="hidden" name="UserType" value="<% =Request.Cookies("sMsource")%>" /><input type="hidden" name="EmployeeType" value="<% =Request.Cookies("sMkeyword")%>" /></form>Can someone point me in the right direction of how to create this logic? Where would it go in the code? Thanks in advance for any help you can offer.

Link to post
Share on other sites

You can find those values in the Request.Form collection. So, Request.Form("YourName") will be the value of that field. How you want to display errors is sort of up to you, but it would make sense to submit the form to the same script that displays it and validate first, then either re-display the form with error messages and previous values filled in, or send the mail or whatever else you do with the data.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...