How can I compare these strings in jQuery?

asifrehman

New Member
This program right now reads in xml code, gets a stock abbreviation, alphabetically sorts them, and then prints them out in an uo list. If you hover over the abbreviations the color will change to red. The goal I'm having is when you hover over an abbreviation, it will show all the data from the xml data just for that company. I tried using the if statement saying if the symbol (abbreviation in xml file) is equivalent to the name (abbreviation in array) then it prints out all the junk for it. The line that prints everything out works correctly in the format I want. I just need to work on the if statement.What I have figured out is I cannot compare two variables with the ==. Keep in mind symbol is an attribute as well, and name is from an array that stores the symbols. I also tried just saying - if(checkPassword(name, symbol)) - and print it all out as I did in the jQuery code below, but that did not work.I put a comment next to the if statement I am working on, it's towards the bottom of the jQuery. HTML:\[code\] <body onload="onBodyLoad()"> <div id="stockList"></div> <br /> <br /> <br /> <div id="stockInfo"></div>\[/code\]jQuery:\[code\]$(document).ready(function () { $.ajax({ type: "GET", url: "stocks.xml", dataType: "xml", success: function (xml) { var companyNames = []; $(xml).find('Stock').each(function () { var symbol = $(this).attr('symbol'); companyNames.push(symbol); }); companyNames.sort(); $.each(companyNames, function (index, name) { $('#stockList').append('<div><li>' + name + '</li></div>'); }); function CheckPassword(val, val2) { var strInput = val.value; var strInput2 = val2.value; if (strInput != strInput2) { val2.focus(); val2.select(); return false; } else return true; } $(xml).find('Stock').each(function () { var company = $(this).find('Company').text(); var symbol = $(this).attr('symbol'); var market = $(this).find('Market').text(); var sector = $(this).find('Sector').text(); var price = $(this).find('Price').text(); var low = $(this).find('Low').text(); var high = $(this).find('High').text(); var amount = $(this).find('Amount').text(); var yieldx = $(this).find('Yield').text(); var frequency = $(this).find('Frequency').text(); $('*').mouseover(function () { $('#stockList li').text($(this).attr('comparison')); }); $('#stockList li').hover( function () { $(this).css({ color: 'red' }); //mouseover if (name == symbol) { // THIS IS THE STATEMENT YOU'RE LOOKING FOR PROGRAMMING GODS $('#stockInfo').append('<div><ol><li>' + "Company = " + company + '</li><br/><li>' + "Market = " + market + '</li><br/><li>' + "Sector = " + sector + '</li><br/><li>' + "Price = " + price + '</li><br/><li>' + "Year Range = " + low + " " + high + '</li></ol><br/>'); } }, function () { $(this).css({ color: 'navy' }); // mouseout $('#stockInfo').empty(); } ); }); } });});\[/code\]XML sample:\[code\]<Products><Stock symbol="GOOG"> <Company>Google</Company> <Market>NASDAQ</Market> <Sector>Software</Sector> <Price>$487.80</Price> <YearRange> <Low>$331.55</Low> <High>$488.50</High> </YearRange> <Dividend available="false"/></Stock><Stock symbol="BA"> <Company>Boeing Company</Company> <Market>NYSE</Market> <Sector>Aerospace</Sector> <Price>$79.05</Price> <YearRange> <Low>$63.70</Low> <High>$89.58</High> </YearRange> <Dividend available="true"> <Amount>$1.20</Amount> <Yield>$1.50</Yield> <Frequency>QTR</Frequency> </Dividend></Stock><Stock symbol="MO"> <Company>Altria Group</Company> <Market>NYSE</Market> <Sector>Comsumables</Sector> <Price>$81.70</Price> <YearRange> <Low>$68.36</Low> <High>$85.00</High> </YearRange> <Dividend available="true"> <Amount>$3.44</Amount> <Yield>$4.2</Yield> <Frequency>ANNUAL</Frequency> </Dividend></Stock></Products>\[/code\]
 
Back
Top