Skip navigation
Currently Being Moderated

Query name property of checkboxes

Aug 18, 2012 5:35 PM

I have a series of checkboxes on a dialog box. I want to loop through the controls and for each checkbox, get the name of the checkbox. I can do the loop portion, but can I query the name property of a control? It seems that the name property returns undefined, even if I had set it when I created the control. Thanks in advance.

 

Rick Quatro

 
Replies
  • Currently Being Moderated
    Aug 19, 2012 5:24 AM   in reply to frameexpert

    You may need to post your code…? I see no name properties for any scriptUI controls…

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 19, 2012 8:26 AM   in reply to Muppet Mark

    Rick, you probably had set a .name property and didn't get an error -- a Javascript oddity. It's usually perfectly valid to do so but because checkboxes are stored internally, custom properties do not get saved.

     

    Perhaps you want to explain why you need a "name". Are your checkboxes not saved in common variables on creation?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 22, 2012 8:18 AM   in reply to frameexpert

    Rick,

     

    This:

     

    var cbx = myDialog.add("checkbox",undefined,"Select Me",{name:"cbx"});

     

    defines a creation property, which is a special kind of property for ScriptUI internal business. You can't tinker with it. To create a custom property, set it separately:

     

    var cbx = myDialog.add("checkbox",undefined,"Select Me",{name:"cbx"});

    cbx.label = 'cbx';

     

    Like Jongware, I'm wondering why why you want to loop through labels to find checkboxes which are defined as variables. If you don't want to use variables and want to use labels to find checkboxes, you could do something like this:

     

    var cbx = myDialog.add("checkbox {text: 'Select Me', label: 'cbx'}");

     

    the do

     

    for (var i = 0; myDialog.children.length; i++)

       {

       if (myDialog.children[i].label == 'cbx')

       // . . .

       }

     

    Or maybe you could use the checkbox's text:

     

    for (var i = 0; myDialog.children.length; i++)

       {

       if (myDialog.children[i].text == 'Select Me')

       // . . .

       }

     

    and forget about custom properties altogether.

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 22, 2012 10:28 AM   in reply to frameexpert

    I wrote

     

    If you don't want to use variables and want to use labels to find checkboxes, you could do something like this:

     

    var cbx = myDialog.add("checkbox {text: 'Select Me', label: 'cbx'}");

     

    But that should have been

     

    myDialog.add("checkbox {text: 'Select Me', label: 'cbx'}");

     

    The whole point being, of course, that if you cycle through controls there's no need to declare them as variables.

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 23, 2012 10:35 PM   in reply to frameexpert

    frameexpert wrote:

     

    var myDialog = new Window("dialog","Form");
    var cbx = myDialog.add("checkbox",undefined,"Select Me",{name:"cbx"});
    myDialog.show();

    alert(myDialog.findElement("cbx"));

    alert(cbx.name);

     

    ...I can't get its name (line 5); it returns "undefined". It seems strange that I can't get a control's name after I set it.

     

    Rick

     

    all ScriptUI objects have a "properties" Property, there's no usage sample in the Guide...to get the check's name use:

     

    alert(cbx.properties.name);
    
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 24, 2012 1:27 AM   in reply to CarlosCanto

    That works only for creation properties. After all, you use "properties" to set creation properties in this (alternative) format:

     

    var cbx = myDialog.add("checkbox {text: 'Select Me', label: 'xyz', properties: {name: 'cbx'}}");

     

    This works: alert(cbx.properties.name);

    This throws an error: alert(cbx.properties.text);

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 24, 2012 8:38 AM   in reply to Peter Kahrel

    correct, that's used to get creation properties only.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points