473,378 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Advanced Form Validation ?

Hi

I have the following form that I need advanced validation on, I would
appreciate any help please.

How can I validate the form so that the user has to select an option
from the select box and if they choose 'other' the focus goes to the
'otherfeedback' textarea which also has to have a value.

<form action="feedback.cfm" method="post" name="form" id="Form"
<select size="1" name="aplan">
<option value="none">-- Select Your Answer --
<option></option>

<option value="More bulletins">More bulletins</option>
<option value="Don't know">Don't know</option>
<option value="Other">Other please specify below</option>
</select>
<p>
<textarea name="otherfeedback" wrap="PHYSICAL" rows="8"
cols="100"></textarea>
</p>
</form>

Thanks in advance for any assistance and time.

Jul 23 '05 #1
4 1524
<ia***@aol.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Hi

I have the following form that I need advanced validation on, I would
appreciate any help please.

How can I validate the form so that the user has to select an option
from the select box and if they choose 'other' the focus goes to the
'otherfeedback' textarea which also has to have a value.

<form action="feedback.cfm" method="post" name="form" id="Form"
<select size="1" name="aplan">
<option value="none">-- Select Your Answer --
<option></option>

<option value="More bulletins">More bulletins</option>
<option value="Don't know">Don't know</option>
<option value="Other">Other please specify below</option>
</select>
<p>
<textarea name="otherfeedback" wrap="PHYSICAL" rows="8"
cols="100"></textarea>
</p>
</form>

Thanks in advance for any assistance and time.


Is this what you're looking for? Watch for word-wrap.

<html>
<head>
<title>other.htm</title>
<script type="text/javascript">
function other() {
var form = document.form;
if (form.aplan.options[4].selected) {
form.otherfeedback.disabled = false;
form.otherfeedback.focus();
} else {
form.otherfeedback.value = "";
form.otherfeedback.disabled = true;
}
}
</script>
</head>
<body>
<form action="feedback.cfm" method="post" name="form" id="Form">
<select size="1" name="aplan" onchange="other()">
<option value="none">-- Select Your Answer --
<option></option>
<option value="More bulletins">More bulletins</option>
<option value="Don't know">Don't know</option>
<option value="Other">Other please specify below</option>
</select>
<p>
<textarea name="otherfeedback" wrap="PHYSICAL" rows="8" cols="100"
disabled></textarea>
</p>
</form>
</body>
</html>
Jul 23 '05 #2
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:B8********************@comcast.com...

[snip]

Here's a version that ensures an option is selected when the form is
submitted.

<html>
<head>
<title>other.htm</title>
<script type="text/javascript">
function other() {
var form = document.form;
if (form.aplan.options[4].selected) {
form.otherfeedback.disabled = false;
form.otherfeedback.focus();
} else {
form.otherfeedback.value = "";
form.otherfeedback.disabled = true;
}
}
function valid() {
var form = document.form;
var what = form.aplan.value;
if (what == "" || what == "none") {
alert("No option selected!");
return false;
}
if (form.aplan.options[4].selected) {
if (form.otherfeedback.value == "") {
alert("No feedback entered!");
return false;
}
}
return true;
}
</script>
</head>
<body>
<form action="feedback.cfm" method="post" name="form" onsubmit="return
valid()">
<select name="aplan" onchange="other()">
<option value="none">-- Select Your Answer --
<option></option>
<option value="More bulletins">More bulletins</option>
<option value="Don't know">Don't know</option>
<option value="Other">Other please specify below</option>
</select>
<p>
<textarea name="otherfeedback" wrap="PHYSICAL" rows="8" cols="100"
disabled></textarea>
</p>
<input type="submit" value="Submit">
</form>
</body>
</html>
Jul 23 '05 #3
Hi

Thanks for the code, however although I can select an item from the
drop down menu, it does not allow me to enter any data into the text
area field if I select 'Other' and the submit button does not appear ?

I am not getting any javascript errors ? so not sure why it is not
working?

Jul 23 '05 #4
<ia***@aol.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hi

Thanks for the code, however although I can select an item from the
drop down menu, it does not allow me to enter any data into the text
area field if I select 'Other' and the submit button does not appear ?

I am not getting any javascript errors ? so not sure why it is not
working?


Can you post your version of the code as mine works (for me).

Also, what browser and version are you using? (Mine's IE5.5.)
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: TG | last post by:
I have a validation form that must behave differently based on the results of a PHP validation check. I have a post command at the top of my form that calls itself. I don't leave the form when...
16
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate...
4
by: Nhmiller | last post by:
This is directly from Access' Help: "About designing a query When you open a query in Design view, or open a form, report, or datasheet and show the Advanced Filter/Sort window (Advanced...
4
by: z. f. | last post by:
Hi, i stated that this is an advanced question because i have a post from few days ago that i received answers to with suggestions that looked good but did not work, so please if you post a...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
1
by: FayeC | last post by:
I am trying to find some tutorials on advanced form validation. I have a form and I have basic validation (empty, value, etc) but I would like to validate some forms to stop people from using the...
2
by: FayeC | last post by:
Can anybody point me to a good tutorial/manual on advanced server-side form validation including validation of fields against unwanted strings such as the use of "http://". Thank you in advance,...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.