![]() |
Javascript Form Verification Issue
Hi guys! I try to learn languages by picking up examples and working my way through them logically, but I'm stuck on a piece of Javascript for form verification. I was wondering if you might be able to help me out.
I'm trying to verify a form with two different types of data-- a text field and a group of radio buttons. Here's the HTML for the form, cleand up to remove some table formatting and other fluff that I don't believe is causing issues: Code:
<form name="myForm" action="mailto:xxx.xxx@xxx.com" method="POST" enctype="text/plain" onsubmit="return validateForm()">Code:
Thanks to y'all, you're always great! |
Not even close:
Code:
var y=document.forms["myForm"]["product"].value;For radio buttons and checkboxes, you can write a function such as this: Code:
function getGroupValue( group )For checkboxes, that will return "" if none are checked and a comma delimited list of value if 1 or more is checked. You would then invoke that via (example from your code): Code:
function validateForm()Text field values, such as opName here, can not be null. They can be blank (""), but never null. And that getGroupValue() function, as written, can't return a null. |
Thanks, I didn't think I was in the right neighborhood-- just trying to come up with a quick, creative solution! I'll give your code a try and post back if I need more assistance. I appreciate the help!
|
By the by, testing for opName == "" is kind of pointless.
A user could enter a single space, just for example, and it won't == "". If you are going to bother to make a test, make it a useful one. There are tons of examples of useful form validation in this very forum. Do a quick search. |
Quote:
Quote:
Quote:
|
Oh, yeah. I know I, for example, have posted essentially that same getGroupValue code (with minor variations, to be sure) at least a dozen times in this forum. And many other members have posted similar stuff. It's here. It just might be hard to guess what keywords to use to find it.
|
| All times are GMT +1. The time now is 12:58 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.