Reading HTML data incorrectly

user3500105

I have a problem here.

I'm wondering why my page is giving the wrong output.

For example,when I tick A ...it displayed C instead of the correct one which was supposed to be A.

Then for the last 3 which are J,K,L...it would not display anything at all.

<!DOC HTML>
<html>
<title></title>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-  
1.4.2.min.css">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="jquery-1.11.0.min.js"></script>
<script src="jquery.cycle.all.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('ul#nav > li').click(function () {
            selfActive = $(this).hasClass("show") ? true : false;
            $(".show").removeClass("show").find("ul").slideDown();
            if (!selfActive) {
                $(this).addClass("show").find("ul").slideDown();
            }

        });
    });
    $(document).ready(function () {
        $("input[name='Option']").change(function () {
            var maxAllowed = 3;
            var cnt = $("input[name='Option']:checked").length;
            if (cnt > maxAllowed) {
                $(this).prop("checked", "");
                alert('You can select maximum ' + maxAllowed + ' phones only!!');
            }
        });
    });
    $(document).ready(function () {
        $('input[type="submit"]').click(function () {
            if ($('input[name=Option]:checked').length > 1) {
                $('.frame-wrapper').fadeOut();
                $('input[name=Option]').each(function () {
                    if ($(this).prop("checked")) {
                        $('.frame-wrapper').eq($(this).index() - 1).fadeIn();
                    }
                });
            }
            else {
                alert("You must compare with more than 1 item.!!");
            }
        });
        $('input[type="compare"]').click(function () {
            $('.frame-wrapper').eq($(this).index() - 1).fadeIn();
        });

    });

</script>
<style type="text/css">
    .frame-wrapper {
        display: none;
        float: left;
        width: 32%;
        margin-top: 20px;
        margin-right: 1%;
        border-radius: 30px;
        background-color: #eee;
    }
    #nav li > ul {
        display: none;
    }
</style>
</head>
<body>
<b>Please select an option</b>
<hr>
<ul id="nav">
    <li>
        <a href="#">Category 1</a>

        <ul>
            <li>
                A <input type="checkbox" name="Option" />
                B <input type="checkbox" name="Option" />
                C  <input type="checkbox" name="Option" />
        </ul>
    </li>
    </ul></hr>
    <hr>

    <ul id="nav">
        <li>
            <a href="#">Category 2</a>

            <ul>
                <li>
                    D <input type="checkbox" name="Option" />
                    E <input type="checkbox" name="Option" />
                    F  <input type="checkbox" name="Option" />
            </ul>
        </li>
        </hr>
        </ul><hr>
        <ul id="nav">
            <li>
                <a href="#">Category 3</a>

                <ul>
                    <li>
                        G <input type="checkbox" name="Option" />
                        H <input type="checkbox" name="Option" />
                        I  <input type="checkbox" name="Option" />
                </ul>
            </li>
            </hr>
            </ul><hr>
            <ul id="nav">
                <li>
                    <a href="#">Category 4</a>

                    <ul>
                        <li>
                            J <input type="checkbox" name="Option" />
                            K <input type="checkbox" name="Option" />
                            L  <input type="checkbox" name="Option" />
                    </ul>
                </li>
                </ul></hr>
                <input type="submit" value="Compare" />
                <form>
                    <input type="button" value="Clear"  
onclick="window.location.href=window.location.href">
                </form>


                <div style="clear: both;"></div>

                <div id="tblA" class="frame-wrapper">
                    <b><em>You Selected A</em></b>
                </div>
                <div id="tblB" class="frame-wrapper">
                    <b><em>You Selected B</em></b>
                </div>
                <div id="tblC" class="frame-wrapper">
                    <b><em>You Selected C</em></b>
                </div>
                <div id="tblD" class="frame-wrapper">
                    <b><em>You Selected D</em></b>
                </div>
                <div id="tblE" class="frame-wrapper">
                    <b><em>You Selected E</em></b>
                </div>
                <div id="tblF" class="frame-wrapper">
                    <b><em>You Selected F</em></b>
                </div>
                <div id="tblG" class="frame-wrapper">
                    <b><em>You Selected G</em></b>
                </div>
                <div id="tblH" class="frame-wrapper">
                    <b><em>You Selected H</em></b>
                </div>
                <div id="tblI" class="frame-wrapper">
                    <b><em>You Selected I</em></b>
                </div>
                <div id="tblJ" class="frame-wrapper">
                    <b><em>You Selected J</em></b>
                </div>
                <div id="tblK" class="frame-wrapper">
                    <b><em>You Selected K</em></b>
                    <div id="tblL" class="frame-wrapper">
                        <b><em>You Selected L</em></b>
                    </div>
                </div>





</body>
</html>
kp singh

I have done a lot of changes in your html/js (bcoz I have some free time :) )

Points to note before copying/pasting:

  1. id should be unique. use class for element
  2. proper doctype and html to use jquery/javascript
  3. only one document.ready() is enough
  4. there are enough jquery selectors to handle form element. you may try that

HTML:

<b>Please select an option</b>
<hr>
<ul class="nav">
<li><a href="#">Category 1</a>
    <ul>
        <li>
            A <input type="checkbox" value="A" name="Option" />
            B <input type="checkbox" value="B" name="Option" />
            C  <input type="checkbox" value="C" name="Option" />
        </li>
    </ul>
</li>
</ul>
<hr>
<ul class="nav">
    <li>
        <a href="#">Category 2</a>
        <ul>
            <li>
                D <input type="checkbox" value="D" name="Option" />
                E <input type="checkbox" value="E" name="Option" />
                F  <input type="checkbox" value="F" name="Option" />
            </li>
        </ul>
    </li>
    </ul><hr>
    <ul class="nav">
        <li>
            <a href="#">Category 3</a>
            <ul>
                <li>
                    G <input type="checkbox" value="G" name="Option" />
                    H <input type="checkbox" value="H" name="Option" />
                    I  <input type="checkbox" value="I" name="Option" />
                </li>
            </ul>
        </li>
        </ul><hr>
        <ul class="nav">
            <li>
                <a href="#">Category 4</a>
                <ul>
                    <li>
                        J <input type="checkbox" value="J" name="Option" />
                        K <input type="checkbox" value="K" name="Option" />
                        L  <input type="checkbox" value="L" name="Option" />
                    </li>
                </ul>
            </li>
            </ul></hr>
            <input type="submit" value="Compare" />
            <div style="clear: both;"></div>
            <div id="tblA" class="frame-wrapper">
                <b><em>You Selected A</em></b>
            </div>
            <div id="tblB" class="frame-wrapper">
                <b><em>You Selected B</em></b>
            </div>
            <div id="tblC" class="frame-wrapper">
                <b><em>You Selected C</em></b>
            </div>
            <div id="tblD" class="frame-wrapper">
                <b><em>You Selected D</em></b>
            </div>
            <div id="tblE" class="frame-wrapper">
                <b><em>You Selected E</em></b>
            </div>
            <div id="tblF" class="frame-wrapper">
                <b><em>You Selected F</em></b>
            </div>
            <div id="tblG" class="frame-wrapper">
                <b><em>You Selected G</em></b>
            </div>
            <div id="tblH" class="frame-wrapper">
                <b><em>You Selected H</em></b>
            </div>
            <div id="tblI" class="frame-wrapper">
                <b><em>You Selected I</em></b>
            </div>
            <div id="tblJ" class="frame-wrapper">
                <b><em>You Selected J</em></b>
            </div>
            <div id="tblK" class="frame-wrapper">
                <b><em>You Selected K</em></b>
            </div>
            <div id="tblL" class="frame-wrapper">
               <b><em>You Selected L</em></b>
            </div>

JS:

$(document).ready(function () {
    $('ul.nav > li').click(function () {
       $(this).find("ul").slideDown();
    });

    $(":checkbox").change(function () {
      var maxAllowed = 3;
      var cnt = $(":checkbox:checked").length;
      if (cnt > maxAllowed) {
         $(this).prop("checked", "");
         alert('maximum ' + maxAllowed);
      }
   });

   $(':submit').click(function () {
      if ($(':checkbox:checked').length > 1) {
          $('.frame-wrapper').fadeOut();
          $(':checkbox').each(function () {
           if ($(this).prop("checked")) {
              $('#tbl' + $(this).val()).fadeIn();
           }
         });
     }
     else {
          alert("You must compare with more than 1 item.!!");
     }
});

});

at last the jsfiddle example also: http://jsfiddle.net/yJ8rV/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

python reading in csv incorrectly

From Dev

reading Excel in Python with win32com - it's incorrectly reading header as first row of data

From Dev

Writing a struct into a file but reading it incorrectly

From Dev

Reading data from a csv file and storing into an array, my file opens correctly however the file is being read incorrectly

From Dev

reading HTML for listed company data into Dataframe

From Dev

Reading data from hive and displaying in HTML

From Dev

Reading data from JSON and display in html

From Dev

Reading HTML into an R data frame using rvest

From Dev

vue renders html incorrectly

From Dev

Reading hex string incorrectly inserted in varchar column

From Dev

Incorrectly Reading a Column Containing Lists in Pandas

From Dev

php excel reader reading numbers incorrectly

From Dev

HTML in JS - Quotes rendered incorrectly

From Dev

Jquery appends dropdown data incorrectly

From Dev

NumPy Reads Binary Data Incorrectly?

From Dev

Fix incorrectly encoded JSON data

From Dev

Reading data from a xml file inside HTML CDATA with PHP

From Dev

Reading CSV file with PHP and display the data in HTML/PHP

From Dev

Jooq select record type seems to be reading columns by index incorrectly

From Dev

Java incorrectly reading accented characters from System.in

From Dev

Python reading string of dictionary incorrectly when using .format()

From Dev

After reading from text file, results are displayed incorrectly

From Dev

Ñ character displaying incorrectly as &#209; in HTML SELECT

From Dev

Html to canvas background color wraps incorrectly

From Dev

Laravel 5.4 MailMessage::action() renders html incorrectly

From Dev

Pure HTML and CSS tabs displaying incorrectly in firefox

From Dev

Firefox displaying <DIV> incorrectly - HTML/CSS

From Dev

HTML input date is being read back "incorrectly"

From Dev

Rails Routing Incorrectly links to show.html

Related Related

  1. 1

    python reading in csv incorrectly

  2. 2

    reading Excel in Python with win32com - it's incorrectly reading header as first row of data

  3. 3

    Writing a struct into a file but reading it incorrectly

  4. 4

    Reading data from a csv file and storing into an array, my file opens correctly however the file is being read incorrectly

  5. 5

    reading HTML for listed company data into Dataframe

  6. 6

    Reading data from hive and displaying in HTML

  7. 7

    Reading data from JSON and display in html

  8. 8

    Reading HTML into an R data frame using rvest

  9. 9

    vue renders html incorrectly

  10. 10

    Reading hex string incorrectly inserted in varchar column

  11. 11

    Incorrectly Reading a Column Containing Lists in Pandas

  12. 12

    php excel reader reading numbers incorrectly

  13. 13

    HTML in JS - Quotes rendered incorrectly

  14. 14

    Jquery appends dropdown data incorrectly

  15. 15

    NumPy Reads Binary Data Incorrectly?

  16. 16

    Fix incorrectly encoded JSON data

  17. 17

    Reading data from a xml file inside HTML CDATA with PHP

  18. 18

    Reading CSV file with PHP and display the data in HTML/PHP

  19. 19

    Jooq select record type seems to be reading columns by index incorrectly

  20. 20

    Java incorrectly reading accented characters from System.in

  21. 21

    Python reading string of dictionary incorrectly when using .format()

  22. 22

    After reading from text file, results are displayed incorrectly

  23. 23

    Ñ character displaying incorrectly as &#209; in HTML SELECT

  24. 24

    Html to canvas background color wraps incorrectly

  25. 25

    Laravel 5.4 MailMessage::action() renders html incorrectly

  26. 26

    Pure HTML and CSS tabs displaying incorrectly in firefox

  27. 27

    Firefox displaying <DIV> incorrectly - HTML/CSS

  28. 28

    HTML input date is being read back "incorrectly"

  29. 29

    Rails Routing Incorrectly links to show.html

HotTag

Archive