Register

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
    Yaz is offline
    Junior Member
    Join Date
    Jul 2003
    Location
    Toronto
    Posts
    21
    Member #
    2327
    Hello!

    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:
    Code:
    var optn = document.createElement("option");
    optn.innerHTML = $("name", this).text();
    optn.value = $("id", this).text();
    $("select#SchoolID").append(optn);
    Method 2:
    Code:
    var optn = document.createElement("option");
    optn.text = $("name", this).text();
    optn.value = $("id", this).text();
    $("select#SchoolID").append(optn);
    Method 2:
    Code:
    var thetxt = $("name", this).text();
    var thevalue = $("id", this).text();
    var newoption = new Option(thetxt,thevalue, false);
    $("select#SchoolID").append(newoption);
    Thanks in advance!
    ..:: Yaz ::..

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    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
    Location
    Bandung, Indonesia
    Posts
    1,207
    Member #
    14572
    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 05:18 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com