Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jquery mobile checkbox generate list

Posted on 2014-02-07
10
Medium Priority
?
602 Views
Last Modified: 2014-03-10
Hi, I'm working in a mobile app and I have this checkboxes, when click in a button it generates a list with the checked options in the same page.  I would like to appear in a new page, but I don't know how to do it.  I will appreciate any help.  Thanks.

Here's the Html

<section class="header_default footer_default" data-role="page" id="setup" data-title="Setup">
        <article data-role="content">
            <form>
                <fieldset data-role="controlgroup" id="hoursName">
                    <legend><strong>Choose your Hours Type:</strong></legend>
                    <input type="checkbox" name="checkboxHours" id="1" value="Regular Hours" >
                    <label for="1">Regular Hours</label>
                    <input type="checkbox" name="checkboxHours" id="2" value="Overtime">
                    <label for="2b">Overtime</label>
                    <input type="checkbox" name="checkboxHours" id="3" value="Travelling">
                    <label for="3">Traveling</label>
                    <input type="checkbox" name="checkboxHours" id="4" value="Training">
                    <label for="4">Training</label>
                    <input type="checkbox" name="checkboxHours" id="5" value="Truck Hours">
                    <label for="5">Truck Hours</label>
                </fieldset>
            </form>
           <button class="ui-btn ui-corner-all addAmount">Add Amount</button>

           <div id="nameList"></div>

        </article><!--content-->     
    </section><!--setup page-->

Open in new window


Here's the Jq:
$(document).on("click", ".addAmount", function(){
&#9;var selectedValues="";
&#9;$checkedCheckboxes = $("input:checkbox[name=checkboxHours]:checked");
&#9;$checkedCheckboxes.each(function () {
&#9;&#9;$('#nameList').append('<li>' + $(this).val() + '</li>');
&#9;});
});

Open in new window

0
Comment
Question by:acbv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
10 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39843607
If you follow this : http://demos.jquerymobile.com/1.4.0/pages/#Multi-pagetemplatestructure

Just put (line 20) <div id="nameList"></div> in the second page
0
 

Author Comment

by:acbv
ID: 39845528
This doesn't work because I'm not trying to open a page with a link, a button retrieves checked checkboxes and populates the list on a div on another page.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39845543
It does matter how you go to the other pages, just the fact that ALL the pages are loaded at the first time
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

Author Comment

by:acbv
ID: 39860498
That doesn't work.
0
 
LVL 43

Expert Comment

by:Rob
ID: 39917103
See here for a working example http://jsbin.com/jisok/1/edit

Essentially you needed to specify that your nameList div to have the "data-role=page" attribute along with moving outside the <section> tag on it's own.

Cheers,

Rob
0
 
LVL 43

Accepted Solution

by:
Rob earned 2000 total points
ID: 39917107
I modified the javascript slightly, mainly by adding the "window.location" line at the end.
$(".addAmount").on("click", function() {
    var selectedValues = "";
    $checkedCheckboxes = $("input:checkbox[name=checkboxHours]:checked");
    $checkedCheckboxes.each(function () {
        $('#nameList').append('<li>' + $(this).val() + '</li>');
    });
    window.location = "#nameList";
});

Open in new window


the html changed to this:
<section class="header_default footer_default" data-role="page" id="setup" data-title="Setup">
        <article data-role="content">
            <form>
                <fieldset data-role="controlgroup" id="hoursName">
                    <legend><strong>Choose your Hours Type:</strong></legend>
                    <input type="checkbox" name="checkboxHours" id="1" value="Regular Hours" >
                    <label for="1">Regular Hours</label>
                    <input type="checkbox" name="checkboxHours" id="2" value="Overtime">
                    <label for="2">Overtime</label>
                    <input type="checkbox" name="checkboxHours" id="3" value="Travelling">
                    <label for="3">Traveling</label>
                    <input type="checkbox" name="checkboxHours" id="4" value="Training">
                    <label for="4">Training</label>
                    <input type="checkbox" name="checkboxHours" id="5" value="Truck Hours">
                    <label for="5">Truck Hours</label>
                </fieldset>
            </form>
           <button class="ui-btn ui-corner-all addAmount">Add Amount</button>


        </article><!--content-->     
    </section><!--setup page-->
           <div data-role="page" id="nameList"></div>

Open in new window

0
 

Author Closing Comment

by:acbv
ID: 39917651
It worked, thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
Owning a franchise can be the dream of a lifetime. It provides a chance for economic growth. You can be as successful as you want.  To make your franchise successful, you need to market it successfully. Here are six of the best marketing strategies …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question