473,387 Members | 1,760 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,387 software developers and data experts.

Dynamic Form Help

I've created a form with several input fields. At the beginning of my
form I use a set of radio buttons to determine how to validate the form as
well as determine what fields are required. Because the form is so lengthy,
I would like to aid users by including visual clues as to what fields
require information by changing the background color of that field to red. I
understand how to accomplish this field by field however, I am looking for
an easier way. Rather that write a big messy function which declares
(document.form.name.style.backgroundColor='red') for every single field, I'd
like to be able to broadcast this command to several chosen fields at once.
Any suggestion would be greatly appreciated.

Best Regards,

Martin Franklin

--
MA********@cox.net
Jul 23 '05 #1
6 1369
MA********@cox.net wrote:
I've created a form with several input fields. At the beginning of my
form I use a set of radio buttons to determine how to validate the form as
well as determine what fields are required. Because the form is so lengthy,
I would like to aid users by including visual clues as to what fields
require information by changing the background color of that field to red. I
understand how to accomplish this field by field however, I am looking for
an easier way. Rather that write a big messy function which declares
(document.form.name.style.backgroundColor='red') for every single field, I'd
like to be able to broadcast this command to several chosen fields at once.
Any suggestion would be greatly appreciated.

Best Regards,

Martin Franklin

Styles? CSS? Perhaps you should try:

comp.infosystems.www.authoring.stylesheets

Fred.
Jul 23 '05 #2
In article <9QDfd.18924$SW3.3086@fed1read01>, MA********@Cox.net enlightened
us with...
I've created a form with several input fields. At the beginning of my
form I use a set of radio buttons to determine how to validate the form as
well as determine what fields are required. Because the form is so lengthy,
I would like to aid users by including visual clues as to what fields
require information by changing the background color of that field to red. I
understand how to accomplish this field by field however, I am looking for
an easier way. Rather that write a big messy function which declares
(document.form.name.style.backgroundColor='red') for every single field, I'd
like to be able to broadcast this command to several chosen fields at once.
Any suggestion would be greatly appreciated.


How to shortcut this depends on how you wrote the function that determines
what fields are required.
If you write that function to shove the elements' names into a little array,
you can loop through the array and change the fields (a foreach or such).

Either way, it's still a list of fields that changes, so you'll have to
change them one by one, whether you're changing the style or class or
whatever. A loop is just cleaner and prettier - not any faster.

--
--
~kaeli~
If you don't pay your exorcist, you get repossessed.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #3
In article <Ba****************@news.optus.net.au>, Oz****@iinet.net.auau
enlightened us with...
MA********@cox.net wrote:
I've created a form with several input fields. At the beginning of my
form I use a set of radio buttons to determine how to validate the form as
well as determine what fields are required. Because the form is so lengthy,
I would like to aid users by including visual clues as to what fields
require information by changing the background color of that field to red. I
understand how to accomplish this field by field however, I am looking for
an easier way. Rather that write a big messy function which declares
(document.form.name.style.backgroundColor='red') for every single field, I'd
like to be able to broadcast this command to several chosen fields at once.
Any suggestion would be greatly appreciated.

Styles? CSS? Perhaps you should try:

That was my first thought, too, but that won't help - he'd still need to
change the class of each one. The required elements change based on which
radio button is chosen by the user.
--
--
~kaeli~
If you don't pay your exorcist, you get repossessed.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #4
kaeli wrote:
[snip]
an easier way. Rather that write a big messy function which declares
(document.form.name.style.backgroundColor='red' ) for every single field, I'd
like to be able to broadcast this command to several chosen fields at once.
Any suggestion would be greatly appreciated.


How about giving each form element an extension to its name that
signifies the options it is mandatory with. Say you have radio buttons
A, B, C and a textarea named "text02". If "text02" is mandatory with
selections A and B, make the name "text02_AB". Do this for every field
that is mandatory for one or more option selections.

Now when radio button with a value 'A' is selected, get all the form
elements:

var els = document.form['aform'].elements

Use a for loop to go through them:

for (var i=0; i<els.length; i++) {
if (els[i].name.match(/A/)){
change background to mandatory colour
} else {
change background to default
}
}

use a regular expression to see if they have an "A" in the name and if
they do, change their class to mandatory or change the background colour
(don't use red, use a pale pink or something soft) or maybe put a border
around them. Any that don't have 'A' in the name are changed to plain.

Of course it means you have to keep the rest of the characters in the
name lowercase, but that shouldn't be too hard. You can use more
complex keys if you want (e.g. add underscores so you get keys _A_ and
_B_ so text02 becomes "text02_A_B_") to provide more flexibility in
naming, but I think it's not necessary.

Cheers, Fred.
Jul 23 '05 #5
Fred...

Excellent suggestion! Thanks for your insight.

Best Regards

Martin

"Fred Oz" <oz****@iinet.net.auau> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
kaeli wrote:
[snip]
an easier way. Rather that write a big messy function which declares
(document.form.name.style.backgroundColor='red' ) for every single field, I'dlike to be able to broadcast this command to several chosen fields at once.Any suggestion would be greatly appreciated.


How about giving each form element an extension to its name that
signifies the options it is mandatory with. Say you have radio buttons
A, B, C and a textarea named "text02". If "text02" is mandatory with
selections A and B, make the name "text02_AB". Do this for every field
that is mandatory for one or more option selections.

Now when radio button with a value 'A' is selected, get all the form
elements:

var els = document.form['aform'].elements

Use a for loop to go through them:

for (var i=0; i<els.length; i++) {
if (els[i].name.match(/A/)){
change background to mandatory colour
} else {
change background to default
}
}

use a regular expression to see if they have an "A" in the name and if
they do, change their class to mandatory or change the background colour
(don't use red, use a pale pink or something soft) or maybe put a border
around them. Any that don't have 'A' in the name are changed to plain.

Of course it means you have to keep the rest of the characters in the
name lowercase, but that shouldn't be too hard. You can use more
complex keys if you want (e.g. add underscores so you get keys _A_ and
_B_ so text02 becomes "text02_A_B_") to provide more flexibility in
naming, but I think it's not necessary.

Cheers, Fred.

Jul 23 '05 #6
I'd like to thank everyone for helping me on this post. Several great
suggestions!

Best Regards

Martin

"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <9QDfd.18924$SW3.3086@fed1read01>, MA********@Cox.net enlightened us with...
I've created a form with several input fields. At the beginning of my form I use a set of radio buttons to determine how to validate the form as well as determine what fields are required. Because the form is so lengthy, I would like to aid users by including visual clues as to what fields
require information by changing the background color of that field to red. I understand how to accomplish this field by field however, I am looking for an easier way. Rather that write a big messy function which declares
(document.form.name.style.backgroundColor='red') for every single field, I'd like to be able to broadcast this command to several chosen fields at once. Any suggestion would be greatly appreciated.

How to shortcut this depends on how you wrote the function that determines
what fields are required.
If you write that function to shove the elements' names into a little

array, you can loop through the array and change the fields (a foreach or such).

Either way, it's still a list of fields that changes, so you'll have to
change them one by one, whether you're changing the style or class or
whatever. A loop is just cleaner and prettier - not any faster.

--
--
~kaeli~
If you don't pay your exorcist, you get repossessed.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #7

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

Similar topics

0
by: Pat Patterson | last post by:
I'm having serious issues with a page I'm developing. I just need some simple help, and was hoping someone might be able to help me out in here. I have a form, that consists of 3 pages of...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
6
by: MikeY | last post by:
Hi Everyone, Does anyone know where I can get my hands on a sample with source code of a simple dynamic button control in C# Windows form. I am looking for a sample that uses a class library...
3
by: Tyler Carver | last post by:
I am trying to use some dynamic controls that are built and then added to tables. The problem that I am having is the timing of when I can populate the controls and have the state remain after a...
7
by: Abraham Luna | last post by:
how do i stop the dynamic validators from breaking explorer if i use a dynamic validator and move to a different control it breaks explorer and i can type in the page when i'm not supposed to....
2
by: deejayquai | last post by:
Hi I'm trying to produce a report based on a dynamic crosstab. Ultimately i'd like the report to actually become a sub report within a student end of year record of achievement. The dynamic...
3
by: RahimAsif | last post by:
I am writing an application that requires the a portion of the main menu to be dynamic. The menu has file, panels, view files and help across the top. The view files sub menu needs to be...
4
by: libish | last post by:
hi all... can any one help me by suggesting a way to get items in dynamic form? here what i'm doing is , i'm displaying a dynamic form. in that form i have a main menu and this main menu contains...
1
by: jmartmem | last post by:
Greetings, I have a nagging problem with client-side dynamic dependent list boxes that perhaps someone can help me troubleshoot. I have a form with a series of dynamic dependent list boxes....
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.