Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Casting Node to HTMLSelect?

    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:
    Code:
    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);
       alert(pvm_select.value);
      }
     }
    }
    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:
    Code:
    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:
    http://krook.org/jsdom/HTMLSelectElement.html
    http://mail-archive.objectweb.org/xm.../msg00078.html

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

    Thanks,
    Sadiq.

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Figured it out...

    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.
    Sadiq.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •