If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3

Thread: Creating

  1. #1
    Yaz is offline
    Junior Member
    Join Date
    Jul 2003
    Member #

    I'm trying to create <option> tags dynamically. These get filled with content from an xml file --I know this part works. Its the creation of the actual <option> tags thats a problem. It does work on Firefox but on IE 7 it only gives me a long dropdown with no text values.

    BTW, I'm using jQuery as well, although I don't think that matters.

    Method 1:
    var optn = document.createElement("option");
    optn.innerHTML = $("name", this).text();
    optn.value = $("id", this).text();
    Method 2:
    var optn = document.createElement("option");
    optn.text = $("name", this).text();
    optn.value = $("id", this).text();
    Method 2:
    var thetxt = $("name", this).text();
    var thevalue = $("id", this).text();
    var newoption = new Option(thetxt,thevalue, false);
    Thanks in advance!
    ..:: Yaz ::..


  3. #2
    Senior Member
    Join Date
    Jun 2005
    Atlanta, GA
    Member #
    1 times
    What does $("name", this) do? Have you tried logging or alerting the value of thetxt?

  4. #3
    Senior Member Steax's Avatar
    Join Date
    Dec 2006
    Bandung, Indonesia
    Member #
    To those who don't know jQuery, using the $("selector") syntax uses a CSS-like selector for the "selector". So $("#header") would select the element with the ID "header". The selected element can then be passed on to the next function.

    The second param of the $ function is context... In other words, it only looks for elements within that context.

    jQuery allows you to make elements on the fly, in a better manner. You can also use the $("element") syntax to generate elements. Like, you can do $("<option value="+value+">"+text+"</option>") and so on, changing variables as you see fit. Then you can simply appendTo it to the selection element.
    Note on code: If I give code, please note that it is simply sample code to demonstrate an effect. It is not meant to be used as-is; that is the programmer's job. I am not responsible to give you support or be held liable for anything that happens when using my code.

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
All times are GMT -6. The time now is 01:50 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: