Using jQuery to pull info from a dropdown and creating a div with that info

Tgrosk

I am running an AB split test that will modify a set of dropdown options for shipping options and creating four div containers with the shipping information inside them. The containers will be side by side boxes that are selectable using a button. I am unable to modify the original html. I need to create this by modifying javaScript and an internal stylesheet.

Here is the html I have to work with:

<div id="carrierCommonDiv">
    <div class="nc_shipping_price_desc">Prices below reflect&nbsp;<span urlPath="/checkout/shipping_policy_popup.jsp?policy=shipping" relativeObj="shippingChargePopup" class="shippingLink3 popLink checkout_popLink">shipping charges</span> for your order.</div>
    <div class="nc_shipping_carrier_select">
        <select id="carrierCode" name="carrierCode">
            <option value="UG" shippingTotal="$13.95" selected="selected" desc="">Standard Ground ( $13.95 )</option>
            <option value="UTS" shippingTotal="$22.45" desc="">Third Day Ground ( $22.45 )</option>
            <option value="US" shippingTotal="$27.45" desc="">Second Day Air ( $27.45 )</option>
            <option value="UNN" shippingTotal="$37.25" desc="">Next Day ( $37.25 )</option>
        </select>
    </div>

Thoughts on how to solve this?

It currently looks like this: http://jsfiddle.net/kBws6/ and should look about like this when completed: http://jsfiddle.net/mMqpG/

KyleMit

This should get you started in jQuery.

Demo in jsFiddle

First, find the select element and save it. Loop through each of it's children. In each loop, you can use $(this) to access all the information you'd need from each option and build some html. Insert it after the select element, and finally hide the original select element:

var $select = $("#carrierCode");
$select.children("option").each(function() {
    var box = "<div class='shipOption' >"+$(this).text()+"</div>";
    $select.after(box);
});
$select.hide();

To add any CSS rules, you should specify the text and then append to the head element. Here's an example of how to do everything in-line, but preferably, you'd create a .css file and link directly to that.

//TEST
$("head").append("<style type='text/css'>"+
                      ".shipOption {"+
                        "height:150px;"+
                        "width:100px;"+
                        "display:inline-block;"+
                        "border:solid 1px #333;"+
                        "text-align:center;"+
                        "float: left;"+
                      "}"+
                  "</style>");

//PROD
$("head").append("<link rel='stylesheet' type='text/css' href='mystyle.css'>");

For click event handling, after you've modified the dom, just setup a listener for click events on anything with the shipOption class:

$(".shipOption").click(function() {
    alert("You clicked "+$(this).attr("value"));
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using jQuery to pull info from a dropdown and creating a div with that info

From Dev

Creating an automatic div with from info

From Dev

How to pull info from a dynamic dropdown of array to post in another table

From Dev

How to pull info from a string and output it?

From Dev

Want to pull variable info from a Comments section

From Dev

Pull out corresponding info from /etc/passwd

From Dev

jQuery Displaying Info Based On Dropdown Information

From Dev

jQuery Displaying Info Based On Dropdown Information

From Dev

Creating a struct from mach_timebase_info()

From Dev

Creating a table with info from another table

From Dev

Get DB content into dropdown and show DB info from selected dropdown

From Dev

Associating Additional Info in DropDown

From Dev

How to pull curl_exec info from string

From Dev

How can I pull user info for posts from two tables?

From Dev

Parse JSON info from Youtube - Jquery

From Dev

store info and pull out in array

From Dev

Need Dropdown to fill out db info on my page using AJAX

From Dev

AddTransient service using info from request

From Dev

Get row info from table using razor

From Dev

retrieve useful info from webpage using JSOUP

From Dev

Display info from a database on a webpage using php

From Dev

Using AJAX to send and receive info from a server

From Dev

retrieve useful info from webpage using JSOUP

From Dev

Getting user info from LDAP by using JAVA

From Dev

Using info from GET request in jQuery to display transformed result through Flask

From Dev

Database query info to dropdown menu

From Dev

jquery ui info into html

From Dev

jquery ui info into html

From Dev

jQuery - setting dropdown option as selected when creating dropdown using jQuery

Related Related

  1. 1

    Using jQuery to pull info from a dropdown and creating a div with that info

  2. 2

    Creating an automatic div with from info

  3. 3

    How to pull info from a dynamic dropdown of array to post in another table

  4. 4

    How to pull info from a string and output it?

  5. 5

    Want to pull variable info from a Comments section

  6. 6

    Pull out corresponding info from /etc/passwd

  7. 7

    jQuery Displaying Info Based On Dropdown Information

  8. 8

    jQuery Displaying Info Based On Dropdown Information

  9. 9

    Creating a struct from mach_timebase_info()

  10. 10

    Creating a table with info from another table

  11. 11

    Get DB content into dropdown and show DB info from selected dropdown

  12. 12

    Associating Additional Info in DropDown

  13. 13

    How to pull curl_exec info from string

  14. 14

    How can I pull user info for posts from two tables?

  15. 15

    Parse JSON info from Youtube - Jquery

  16. 16

    store info and pull out in array

  17. 17

    Need Dropdown to fill out db info on my page using AJAX

  18. 18

    AddTransient service using info from request

  19. 19

    Get row info from table using razor

  20. 20

    retrieve useful info from webpage using JSOUP

  21. 21

    Display info from a database on a webpage using php

  22. 22

    Using AJAX to send and receive info from a server

  23. 23

    retrieve useful info from webpage using JSOUP

  24. 24

    Getting user info from LDAP by using JAVA

  25. 25

    Using info from GET request in jQuery to display transformed result through Flask

  26. 26

    Database query info to dropdown menu

  27. 27

    jquery ui info into html

  28. 28

    jquery ui info into html

  29. 29

    jQuery - setting dropdown option as selected when creating dropdown using jQuery

HotTag

Archive