Solved

java script

Posted on 2012-03-26
1
216 Views
Last Modified: 2012-06-21
wondering with simple Javascript function how to fetch with AJAX the file sample.html and Sort the contents of sample.html by price
sample.html
0
Comment
Question by:pal2k
[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
1 Comment
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 37768145
Something like this?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>	
 <title>Untitled</title> 
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
</head>

<body>
    <input type="button" onclick="javascript:display()" value="display in order" />
    <div id="sampleHtml"></div>
<script type="text/javascript">
    $.ajaxSetup ({
		cache: false
	});
	var cities = new Array();
	var amts = new Array();
	$(document).ready(function(){
	    $.get('Sample.html', function(data) {
            $('#sampleHtml').html(data);
            $('#sampleHtml').find("div[id^='hotel_id']").each(function(){
                $(this).children('div').each(function(i){
                    if(i == 1){
                        amts.push($(this).find('span').text());
                    }else{
                        cities.push($(this).find('span').text());
                    }
                });
            });
        });
	});
function display(){
    var cityAmts = new Array();
    for(i=0; i<amts.length; i++){
        cityAmts[amts[i]] = cities[i];        
    }
    amts.sort(sortfunc);
    for(j=0; j<amts.length; j++){
        document.getElementById("sampleHtml").innerHTML += cityAmts[amts[j]] + ", " + amts[j]  +  '<br/>';
    }    
}
function sortfunc(a,b)
{
return a - b;
}
</script>
</body>
</html>

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SharePoint and CAML query help 4 26
replacing inline javascript with jquery 4 63
Need help with a stick header please 12 30
Error just appeared 3 23
This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

752 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