/    Sign up×
Community /Pin to ProfileBookmark

Create Combo Boxes on the Fly

Hello

I am trying to create some code that will allow me to create combo boxes programmatically. When a user selects something from a combo box I would like another one to appear and again when something is selected from the new combo box etc. I have found a way to make them appear visible when selected but this will not help as I do not know the maximum number of combo boxes I need.

Can anyone help me with this please? Thank you.

to post a comment
JavaScript

28 Comments(s)

Copy linkTweet thisAlerts:
@CharlesJun 08.2006 — It's easily done with JavaScript but not everybody uses JavaScript. About one in ten do not. You'll need to find a redundant, JavaScript free version and that's not easy.
Copy linkTweet thisAlerts:
@phpnoviceJun 08.2006 — Can anyone help me with this please? Thank you.[/QUOTE]
I've never used the DOM "method" approach to this before -- only the [b]innerHTML[/b] property. So, start with the following as a trial:

var sel = document.CreateElement("SELECT");

sel.name = "mySelect";

sel.options[sel.options.length] = new Option("[select one]", "", false, false);

document.body.appendChild(sel);
Copy linkTweet thisAlerts:
@tomMonkeyauthorJun 12.2006 — Thank you I will give that a try today
Copy linkTweet thisAlerts:
@tomMonkeyauthorJun 12.2006 — When I try this:

<html>

<head>

<title>New Page 1</title>

</head>

<body>

<select id="cboA" onChange="boxappear()">

<option>Test A</option>

<option>Test B</option>

<option>Test C</option>

</select>

</body>

<script>

function boxappear() {

var sel = document.CreateElement("SELECT");

sel.name = "mySelect";

sel.options[sel.options.length] = new Option("[select one]", "", false, false);

document.body.appendChild(sel);

}

</script>

</html>

I get the error message: Object doesn't support this propert or message

For this line: var sel = document.CreateElement("SELECT");

Do you know why this is please?
Copy linkTweet thisAlerts:
@CharlesJun 12.2006 — Because the [font=monospace]document[/font] object has no [font=monospace]CreateElement[/font] method.

http://www.w3.org/TR/REC-DOM-Level-1/

That link will give you a bit more information that you are seeking, but not more than you need. Chapter one details the method that you are trying to use, chapter two has some easier ways.

But stop trying to make a page that doesn't work for one out of every ten users!
Copy linkTweet thisAlerts:
@tomMonkeyauthorJun 12.2006 — Thanks Charles. In response to your compatablity issue this is a password protected website for a select few companies. I think there are only nine involved so statistically I should be ok!
Copy linkTweet thisAlerts:
@CharlesJun 12.2006 — so statistically I should be ok![/QUOTE]Perhaps, but legally you might be in trouble. If this is for one or more business then you might be running afoul of accessibility laws - people with certain disabilities cannot use browsers with JavaScript. Do consult an accessibility lawyer in your area.
Copy linkTweet thisAlerts:
@tomMonkeyauthorJun 12.2006 — No it's ok, it's not a commercial venture. It's to do with engineers sharing error data. they all have IT deptarments who can give them a machine that runs script. thanks for the warning though.
Copy linkTweet thisAlerts:
@CharlesJun 12.2006 — Laws differer from country to country but in the US that would be considered employment discrimination under the Americans with Disabilities Act if any company has 15 or more employees.
Copy linkTweet thisAlerts:
@phpnoviceJun 12.2006 — Somebody really needs to get a life -- elsewhere -- instead of harassing people in a JavaScript forum. People have brains of their own. A simple heads-up is one thing. Carrying on through three different posts is quite another. People don't need a mother. It's quite ludicrous how some people think that nobody else, besides themselves, can give proper consideration to what is needed in their professional endeavors. :rolleyes:
Copy linkTweet thisAlerts:
@CharlesJun 12.2006 — Every endevor has side effects, and it is the job of the Engineer to take those side effects into account.

And it is only human decency to warn somebody that they might be unintentionally causing harm to somebody.

And it is the responsibility of every citizen to warn somebody when they might be unintentionally violating the law.
Copy linkTweet thisAlerts:
@phpnoviceJun 12.2006 — And it is only human decency to warn somebody that they might be unintentionally causing harm to somebody.

And it is the responsibility of every citizen to warn somebody when they might be unintentionally violating the law.[/QUOTE]

Like I said, a heads-up is one thing, but carrying on through three posts (now more) is being a busy-body, sticking your nose in where it is neither welcome nor needed. The guy did everything but tell you to mind your own business two times -- yet you persisted. So, give it up already. You've proved you can be a mother, now why don't you prove you are able to do the mature thing and let it go. :rolleyes:

This is not even a heads-up. It is rudely sticking your nose in where it doesn't belong:
But stop trying to make a page that doesn't work for one out of every ten users![/QUOTE]
Again, this is not even a heads-up. It is rudely sticking your nose in where it doesn't belong:
Perhaps, but legally you might be in trouble.[/QUOTE]
Lastly, THIS IS A JAVASCRIPT FORUM!!! Not a seminar on world legal issues.
Laws differer from country to country but in the US that would be considered employment discrimination under the Americans with Disabilities Act if any company has 15 or more employees.[/QUOTE]
People come here to learn JavaScript. Perhaps you should be telling the adminstration of this site that having a JavaScript forum for the purpose of teaching people to use JavaScript can make them liable because someone might go away from here and misuse JavaScript to the point that somebody might bring a lawsuit against all parties from the programmer all the way back to every teacher and forum that taught that programmer how to (mis)use JavaScript. :rolleyes:

And before you get off on that tack... No, the purpose of this forum is NOT to teach people the legal ramifications of using JavaScript. There is no person, that visits this site, that is qualified to do that -- and that includes you. It wasn't too long ago that you and your retentive bunch were citing that law (which I don't even care to remember the number of) as proof-positive that it was against the law for *anybody* to create web pages that were dependent upon JavaScript for their major function. I got tired of hearing that malarkey and went and read that law myself. Well, as it turns out, it very plainly states that it applies *only* to the federal government. Yet, you and your retentives were citing it [I]carte blanche[/I] against anybody and everybody (I'm exaggerating only slightly, here) that asked a question in this forum. So! YOU ARE NOT QUALIFIED TO SPEAK ON *ANY* LEGAL ISSUES IF YOU CAN"T EVEN GET ONE LAW STRAIGHT!

Now, shove off. Grief! I'm tired of hearing your diarrhea of the mouth on this subject!
Copy linkTweet thisAlerts:
@CharlesJun 12.2006 —  Well, as it turns out, it very plainly states that it applies *only* to the federal government.[/QUOTE]You must have read the wrond law or the law wrong. The ADA has three titles, one applies to governments, and there has been some litigation about that title's application to non-federal parts. But the other two titles, one applies the law to "public accomodation", which includes commerce, and the other to employment. Target is currently being sued for its inaccessible web site under the ADA.

I never wrote that one ought not to use JavaScript, I've simply been advocating for, and helping people to, use JavaScript is a way that doesn't cause harm.

Again, please read things more carefully. You'll note that I brought the matter up several times, each to correct a mis-understanding.

And just why are you disturbed by my pointing out the possible down side to a particular way of doing things?
Copy linkTweet thisAlerts:
@phpnoviceJun 12.2006 — And just why are you disturbed by my pointing out the possible down side to a particular way of doing things?[/QUOTE]
It's not me that is misreading things -- as witnessed by that statement. This is like the misguided lawyer that asks a man in a divorce case, "When did you quit beating your wife?" You, like he, presume too much. This is not a forum for your personal diatribes. If that is not your intent, then you better go back to school and learn some manners. And, if you don't like my diatribes against you, keep in mind that mine would be non-existent without yours. It is also not like I am the only one that doesn't like what you are doing. I've seen many other bitter denunciations of your tactics. You'd think that some people would get it through their heads, after a while, that it is not everybody else...
Copy linkTweet thisAlerts:
@CharlesJun 12.2006 — It's not me that is misreading things[/QUOTE]From the U.S. Equal Employment Opportunity Commission, U.S. Department of Justice,

Civil Rights Division:The title I employment provisions apply to private employers, State and local governments, employment agencies, and labor unions. Employers with 25 or more employees were covered as of July 26, 1992. Employers with 15 or more employees were covered two years later, beginning July 26, 1994.[/quote]Title II of the ADA prohibits discrimination against qualified individuals with disabilities in all programs, activities, and services of public entities. It applies to all State and local governments, their departments and agencies, and any other instrumentalities or special purpose districts of State or local governments. It clarifies the requirements of section 504 of the Rehabilitation Act of 1973 for public transportation systems that receive Federal financial assistance, and extends coverage to all public entities that provide public transportation, whether or not they receive Federal financial assistance. It establishes detailed standards for the operation of public transit systems, including commuter and intercity rail (AMTRAK).[/quote]A public accommodation is a private entity that owns, operates, leases, or leases to, a place of public accommodation. Places of public accommodation include a wide range of entities, such as restaurants, hotels, theaters, doctors' offices, pharmacies, retail stores, museums, libraries, parks, private schools, and day care centers. Private clubs and religious organizations are exempt from the ADA's title III requirements for public accommodations.[/quote]http://www.usdoj.gov/crt/ada/qandaeng.htm
Copy linkTweet thisAlerts:
@phpnoviceJun 12.2006 — From the U.S. Equal Employment Opportunity [blah, blah, blah, blah, blah]...[/QUOTE]
You're missing the point altogether. The issue isn't about what laws are or are not on the books -- or whether such laws apply. The issue is about you turning a JavaScript forum into a place where you and your retentives actually stoop to threatening those trying to learn JavaScript with dire predictions of legal action and law suits. Yes, you have done that and so has Vlady and Felgal just to name three.
Copy linkTweet thisAlerts:
@CharlesJun 12.2006 — From the [i]Jupitermedia AUP Agreement[/i]You will not use these forums to violate any laws nor to discuss illegal activities.[/quote]http://www.jupitermedia.com/corporate/privacy/aup.html
Copy linkTweet thisAlerts:
@phpnoviceJun 12.2006 — You are so far off the mark and reaching so far afield in a futile attempt to justify your indecent actions that it isn't even funny. Teaching someone JavaScript is in no way illegal and absolutely violates no laws. As I have already stated, a simple heads-up is all that is decently required in order to absolve yourself of any responsibility for what someone else does with the information you impart.

And, they have a criminal term for those that feel the need to threaten others. ?
Copy linkTweet thisAlerts:
@A1ien51Jun 12.2006 — Charles,

I think you need to step away. That rule really applies to "How do I remove the banner ads from my free site." or "how do I click adsense ads automatically" type of posts. Not that you will be sued by a person that has to use a screen reader that is poorly designed. Yes these are problems people need to know about, but they do not need to be force fed stuff.

I know you are volunteering your time, but you need to step back and let common sense kick in.

I saw this same sort of thing happen in Best Buy yesterday. An assitant manager was harrasing a customer because he did not want the cooktop cleaner for his newly bought stove. He keep pushing stuff on him and kept telling him X and Y and don't come back if you have problems since the warranty does not cover it. The guy walked away without buying the $1200.00 stove. Money out of the stores pocket all because of a $6.99 bottle of cleaner.

That is the exact same thing that is happening here. You are pushing what you think is right on people too hard. A simple comment is all you need. Egging on people with you have to do this will make people leave this friendly forum. I know you are very helpful around here!

I have no power here, but I just thought I would try to point out a small problem before it grows even more out of control than it already has.

phpnovice,

Adding fuel to the fire does not help either!

Keep it friendly!

Eric Pascarello
Copy linkTweet thisAlerts:
@phpnoviceJun 13.2006 — phpnovice,

Adding fuel to the fire does not help either![/QUOTE]

I know. It is just hard to turn my back and ignore some things.

Cheers.
Copy linkTweet thisAlerts:
@phpnoviceJun 13.2006 — I get the error message: Object doesn't support this propert or message

For this line: var sel = document.CreateElement("SELECT");

Do you know why this is please?[/QUOTE]

Sorry. I accidentally capitalized the method name where I shouldn't have. As I'm sure you've figured out by now, that should have been as follows:

var sel = document.createElement("SELECT");
Copy linkTweet thisAlerts:
@CharlesJun 13.2006 — You are so far off the mark and reaching so far afield in a futile attempt to justify your indecent actions that it isn't even funny. Teaching someone JavaScript is in no way illegal and absolutely violates no laws. As I have already stated, a simple heads-up is all that is decently required in order to absolve yourself of any responsibility for what someone else does with the information you impart.

And, they have a criminal term for those that feel the need to threaten others. ?[/QUOTE]
You’re at the pistol range and somebody has asked you to show her how to shoot. Naturally, you start with the preliminary safety instructions. Now, imagine that some guy nearby overhears and starts to berate you - you’re supposed to be teaching her how to shoot, not how to handle a gun safely. If she had wanted a safety course she could have signed up for one. You would think that this guy was a dangerous idiot and hope that the management would evict him. Safety is, after all, integral to everything that you do with a gun – or any other tool that might cause harm.

From time to time the answer to some JavaScript question is to use CSS; it’s easier and better supported. I’ve never seen a complaint about discussing CSS in the JavaScript forum. And from time to time it is pointed out that some script will not work on minority browsers like FireFox or Opera and without objection.

What is it about accessibility that so enrages some people? It can’t be that it sometimes requires a non-JavaScript solution to a problem and it can’t be that it requires extra effort for the benefit of some minority. All that I can think of is that some people have a very deep animus concerning that minority – one so deep that they feel the need to protect others for the very thought of them and their needs. And I have a idea of what a just God will do to such people.
Copy linkTweet thisAlerts:
@CharlesJun 13.2006 — Thanks to an anonymous user and this page http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/createelement.asp[/QUOTE]Do be careful with Microsoft documentation - it can be a little Microsoft specific. That link that I posted above, http://www.w3.org/TR/REC-DOM-Level-1/ , might be a little more cross-browser. But it is a good bit more difficult to read and, after all, JavaScript itself doesn't work cross-browser.
Copy linkTweet thisAlerts:
@phpnoviceJun 13.2006 — What is it about accessibility that so enrages some people?[/QUOTE]
Neither your example nor your conclusion apply to the situation. You've lost your argument, Charles. The tides are against you. You continue to harp on those things that are not at issue -- and never were. Will you ever get it straight, Charles? It seems not.

Cheers.
Copy linkTweet thisAlerts:
@CharlesJun 13.2006 — Argument? I thought that you were trying to convince me of something - and you certainly haven't done that.
Copy linkTweet thisAlerts:
@LeeUJun 13.2006 — Alright, guys. Let's play nice. I think you're way off topic by this time. Let's keep a friendly discussion here and back on topic or I will have to close the thread.
Copy linkTweet thisAlerts:
@phpnoviceJun 13.2006 — A1ien51 proved my point. That is good enough. ?

Cheers.
×

Success!

Help @tomMonkey spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...