View Full Version : Casting Node to HTMLSelect?

03-02-2004, 08:02 PM
Hey all,

I'm having some trouble with a select box.

I've got some dynamic stuff happening using DOM, in that I create various fields on the fly. One of those fields is a select box. As a matter of fact, that select box is an array.

Let's call that array property_value_method[].

I want to use DOM to cycle through this array of select boxes.

Here's what I got so far:

function displayProperties() {
var pvm_list = document.getElementsByTagName("select");
for(var i = 0; i < pvm_list.length; i++) {
var pot_node = pvm_list.item(i);
if(pot_node.attributes.getNamedItem("name").value.match("property_value_method")) {
var pvm_select = (HTMLSelectElement)pot_node.cloneNode(true);

I want to get the value out, or even just get access to the selectedIndex or something, but I can't seem to cast it correctly.

I know that I've got the right pot_node (stands for potential node if you were wondering...), and I know that it is in fact a select box, but I want to know what the correct syntax is for casting this thing.

At least I think casting is the problem. If anyone can see some other problem, I'd appreciate the help.

One other implication if you were wondering why I don't just use:

for(var value in document.forms["app"].elements) {
if(value.match("property_value_method")) {

is because I am using PHP and a field_forwarder, so I've potentially got more than one field named property_value_method[0], etc.. so that's why I'm resorting to using DOM to grab that information.

Here are some of my resources:

the cloneNode approach didn't work for me...


03-02-2004, 08:10 PM
Hah, what a joke.

Sorry for bugging you guys with that long post.

So it turns out you don't need to cast it.

Executing pot_node.value and pot_node.selectedIndex works just fine without needing to cast it.

Not sure how that works, but yea.....

Thanks again to anyone that thought to help.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum