for an unselected value. Doesn't really matter which you use, just pick one
and stick with it. In addition you'll want to validate on the server side
to prevent errors from users without JS.
Also, if you are going to be doing alot of field dependant JS, and
validation in your forms, you might want to check out qForms at
www.pengoworks.com. Does almost all of the validation for you and will also
help you write routines for "if/then" form dependencies.
-Cameron
-----------------
Cameron Childress
Sumo Consulting Inc
---
land: 858.509.3098
cell: 678.637.5072
aim: cameroncf
email: [EMAIL PROTECTED]
-----Original Message-----
From: Bruce Sorge [mailto:[EMAIL PROTECTED]
Sent: Saturday, February 07, 2004 2:29 PM
To: CF-Talk
Subject: Re: Please make selection ----->
For select lists, I use this:
<script language="_javascript_">
//Need to check and see that if they selected something other than an empty
("") field
function checkFormSelect() {
Var= FormName.FieldName.selectedIndex;
if (FormName.FieldName.options[Var].value == "") {
alert("Enter alert message here");
return false;
}
else
{
return True;
}
}
</script>
<body>
<form name="FormName" method="get" action="" > checkFormSelect()">
<Select name="FieldName">
<option value="">Please Select an Item
<option value="ThisItem">This Item
</SELECT>
<BR>
<input type="Submit">
</form>
In your Form tag, just use the onSubmit variable. If the field is selected
with something other than an empty variable, it will submit, otherwise it
will return false and show the user the error message. You can also add a
focus attribute to the script to focus them onto the select list.
For the other part, you can use _javascript_ and a div tag:
<script>
//This script will trigger three text fields if the caller has called in
before.
function hide ( name ) {
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
W3C = (document.getElementById) ? 1 : 0;
if (W3C) {
document.getElementById(name).style.visibility = "hidden";
} else if (NS4) {
document.layers[name].visibility = "hidden";
} else {
document.all[name].style.visibility = "hidden";
}
}
function showlayer (name ) {
var currentX, //mouse position on X axis
currentY, //mouse position on X axis
x, //layer target position on X axis
y, //layer target position on Y axis
docWidth, //width of current frame
docHeight, //height of current frame
layerWidth, //width of popup layer
layerHeight; //height of popup layer
var ele; //points to the popup element
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
W3C = (document.getElementById) ? 1 : 0;
// First let's initialize our variables
if ( W3C ) {
//alert("w3c");
ele = document.getElementById(name);
docWidth = document.width;
docHeight = document.height;
layerWidth = ele.style.width;
layerHeight = ele.style.height;
} else if ( NS4 ) {
ele = document.layers[name];
docWidth = document.width;
docHeight = document.height;
layerWidth = ele.clip.width;
layerHeight = ele.clip.height;
} else { // meant for IE4
ele = window.opener.document.all[name];
docHeight = document.body.offsetHeight;
docWidth = document.body.offsetWidth;
layerWidth = 200;
layerHeight = ele.offsetHeight;
}
if ( NS4 ) {
ele.visibility = "show";
} else { // IE4 & W3C
ele.style.visibility = "visible";
}
}
</script>
<td class="td" align="left">
<input type= radio name = Action value = NewCustomer checked
> No
<input type= radio name = Action value = CurrentCustomer
> Yes
<div style="visibility:hidden" id="divName">
Enter User Name <input type= text name=LoginID size=10
target=_parent><BR>
Enter First Name <input type="text" name="Fname" size="10"
target=_parent><BR>
Enter Last Name <input type="text" name="Lname" size="10"
target=_parent>
</div>
</td>
Although this is for radio buttons and text fields, you can modify it to use
select lists.
Hope this helps,
Bruce
----- Original Message -----
From: Stuart Kidd
To: CF-Talk
Sent: Saturday, February 07, 2004 3:44 PM
Subject: Please make selection ----->
Hi guys,
With usual text boxes in forms, CF can make sure the user has filled
them in but how can I get it to make sure with select boxes the user
doesn't leave the default "Please make selection----->" part selected
(which will of course bring up an error in the action page). Isn't
there a way I can fix errors on the initial page?
Also, a little off topic, but is there a way with Dreamweaver to display
certain select boxes only if others are selected. For instance if they
select "For Rent" the next select box for price will be a list of
"Weekly Price" and "Monthly Price" and then followed by a text box for
the user to insert price. But had they chose "For Sale" then the next
select box would be just the price text box.
Thanks,
Stuart (Saturday night at home)
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

