hamburgerlove413 Posted April 18, 2014 Share Posted April 18, 2014 Hello, i wasn't sure of a good way to title this post but, I have this app that for right now, you type in band name and it grabs that band's concerts from last.fm API (without using a submit button). This part works, but then when i type a new band/artist in to the input box, instead of replacing the previous band's concerts, it just adds to it. Does anyone know of a way to delete the previous information once a new band name is typed in? the html: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Assignment 03 Mashup – Nicholas Barna</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="js/script.js"></script> <link href="css/styles.css" rel="stylesheet" type="text/css"> </head> <body> <div id="container" class="globalWidth"> <form name="artistSearch" id="artistSearch" method="get"> <label for="artistName">Artist or band name:<input type="text" name="artistName" id="artistName" /></label> </form> <span id="searchTitle">search for:</span><span id="searchItem"></span> <div id="artist"> </div> </div> </body> </html> the Javascript: $(document).ready(function () { $("#artistName").on("keyup change", function() { artistName = this.value; $.get("http://ws.audioscrobbler.com/2.0/?method=artist.getevents&artist=" + artistName + "&api_key=69d935120d26cbcbaeed4fac6f59dfb6", function(xml) { $(xml).find("venue").each( function() { title = $(this).find("name").text(); $("#artist").append(title); }); }); $("#searchItem").text(this.value); }); }); Quote Link to comment https://forums.phpfreaks.com/topic/287871-clearing-information/ Share on other sites More sharing options...
hamburgerlove413 Posted April 18, 2014 Author Share Posted April 18, 2014 Also, is there a way to do something like "when this API has sent back a response with xml in it, do this"? Quote Link to comment https://forums.phpfreaks.com/topic/287871-clearing-information/#findComment-1476611 Share on other sites More sharing options...
dalecosp Posted April 18, 2014 Share Posted April 18, 2014 I'm fighting with this right now also; I'd really like to avoid keyup() ...Wondering if setting a timer after keyup() is the solution... have you tried to make "onchange" work instead? Quote Link to comment https://forums.phpfreaks.com/topic/287871-clearing-information/#findComment-1476617 Share on other sites More sharing options...
possien Posted April 18, 2014 Share Posted April 18, 2014 Your last line of code will keep appending the content with the previous content. Try something like: $("#artist").html(title); Quote Link to comment https://forums.phpfreaks.com/topic/287871-clearing-information/#findComment-1476618 Share on other sites More sharing options...
hamburgerlove413 Posted April 18, 2014 Author Share Posted April 18, 2014 well, the problem with changing append is that I need it to append so I can build a list of the events. It's only when I change the band name in the input box that I would like all of that to clear. I haven't tried onchange yet. Quote Link to comment https://forums.phpfreaks.com/topic/287871-clearing-information/#findComment-1476619 Share on other sites More sharing options...
possien Posted April 18, 2014 Share Posted April 18, 2014 So if the input box changes you want it to clear the value of 'title' and start new. You would have to compare the value of the text box to the previous input but you are hard coding the url for query. Does the url change? Quote Link to comment https://forums.phpfreaks.com/topic/287871-clearing-information/#findComment-1476627 Share on other sites More sharing options...
hamburgerlove413 Posted April 18, 2014 Author Share Posted April 18, 2014 No, the url stays the same Quote Link to comment https://forums.phpfreaks.com/topic/287871-clearing-information/#findComment-1476629 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.