control type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • quickcur@yahoo.com

    control type

    hi, if I do

    var f = document.forms['myform'].elements['myele'];

    how can I tell f is a text, select, or radio?

    Thanks,

    qq

  • Ian Collins

    #2
    Re: control type

    quickcur@yahoo. com wrote:
    hi, if I do
    >
    var f = document.forms['myform'].elements['myele'];
    >
    how can I tell f is a text, select, or radio?
    >
    f.nodeName.toLo werCase();
    f.tagName.toLow erCase();

    The toLowerCase() is required because IE converts nodeName to upper case
    and FF doesn't, at least for nodeName. I haven't checked with tagName.

    --
    Ian Collins.

    Comment

    • RobG

      #3
      Re: control type

      quickcur@yahoo. com wrote:
      hi, if I do
      >
      var f = document.forms['myform'].elements['myele'];
      >
      how can I tell f is a text, select, or radio?
      alert(f.type);


      --
      Rob

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: control type

        "quickcur@yahoo .com" <quickcur@yahoo .comwrites:
        var f = document.forms['myform'].elements['myele'];
        >
        how can I tell f is a text, select, or radio?
        Each form control has a "type" property, whether it is an input,
        select, button or textarea element.

        For input and button elements, you specify the type in the type
        attribute already. Textarea elements only gas the type "textarea",
        and select elements have the types "select-one" and "select-multiple"
        depending on the "multiple" attribute.

        So, to check for text, select or radio:

        if (f.type == "text") { // text
        } else if (f.type == radio) { // radio
        } else if (f.type.substri ng(0,7) == "select-") { // select
        }

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        Working...