/    Sign up×
Community /Pin to ProfileBookmark

hi all..

i have a problem with dynamicly creating options as children for a select object. they appear to be created but i don;t see the values in the pull down?! i see that there are options when opening the menu but the name of the option – the ‘text’ parameter – is not visible.
if i pass the value – it is in the POST array but i still need to see it to select it.

how do i do that?

and also if the ‘disabled’ attribute for the select is ‘true’ how do i turn it off?
i tried:
ob.setAttribute(‘disabled’,false);
ob.setAttribute(‘disabled’,0);
ob.setAttribute(‘disabled’,’false’);
etc….

doesn;t do it… either on firefox or ie….

thanks….

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@KorFeb 07.2007 — 
  • 1. Show us your code which creates dynamic the options


  • 2. You may use either DOM 1 methods

    [COLOR="Navy"]ob.removeAttribute('disabled')[/COLOR]

    or DOM 0 methods

    [COLOR="Navy"]ob.disabled=false;[/COLOR]


  • In XHTML (and W3 recommendation) disabled can not be minimized and it has only a single value disabled="disabled", so for a comprehensive solution, probably DOM 1 is a good ideea

    to disable:

    [COLOR="Navy"]ob.setAttribute('disabled','disabled')[/COLOR]

    to enable

    [COLOR="Navy"]ob.removeAttribute('disabled')[/COLOR]

    It is the same for readonly, checked, selected, noresize:
    <i>
    </i>&lt;input checked="checked" /&gt;
    &lt;input readonly="readonly" /&gt;
    &lt;input disabled="disabled" /&gt;
    &lt;option selected="selected" /&gt;
    &lt;frame noresize="noresize" /&gt;

    IE needs camel case, thus for the special case of readonly, the syntax should be:

    [COLOR="Navy"]ob.setAttribute('readOnly','readonly')

    ob.removeAttribute('readOnly')[/COLOR]
    Copy linkTweet thisAlerts:
    @toshogauthorFeb 07.2007 — ok... here is the options chunk...

    for(i=0;i<2;i++) {

    // alert(str.length);

    var new_option = document.createElement('option');

    new_option.setAttribute('value',str[0]);

    new_option.setAttribute('text',str[0]);

    ob.appendChild(new_option);

    }


    str is an array of strings...

    ob is the select object....

    thanks...
    Copy linkTweet thisAlerts:
    @toshogauthorFeb 08.2007 — ok.. i got it working on mozilla... but ie blows... it doesn;t display the names of the option - the 'text' atribute. the code that works on mozilla and safari is:
    <i>
    </i> for(i=0;i&lt;str.length;i++) {
    // alert(str.length);
    var new_option = document.createElement('option');
    new_option.value= str[i];
    new_option.text = str[i];
    ob.appendChild(new_option);
    }


    so how do i make the retarded ie get it?

    thanks...
    Copy linkTweet thisAlerts:
    @XeelFeb 08.2007 — Don't make your life more difficult than it is.

    When creating a new option:

    selectElement.options[index] = new Option(String name, String value);

    where index is your new/old index where the option text and value should appear.

    To clean select element options list just execute:

    selectElement.length = 0;

    That works in all browsers and text and value are rendered correctly.
    Copy linkTweet thisAlerts:
    @toshogauthorFeb 08.2007 — thanks.
    ×

    Success!

    Help @toshog 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 5.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: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

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

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...