yeah i figured that out, but still have some problems though.
I found a way to filter, but its not ideal just yet. It's something i
found on the internet but it works with some sort of array
(respone.values). To receive the objects in the array there is an
other function needed. This just seems way to difficult , there must
be an easier way where i do not need an extra function no?

<script language="javascript" type="text/javascript">

$(function() {
        $("input").next("#prijs").hide();
        $("#naam").blur(function () {
            $.getJSON("producten.js", function(json) {
                        /* Parse JSON objects */
                              jJSON["prijs"] = (function() {
                            response = {
                                values:[],
                            };

                            $.each(json.channel.items,function(i,item) {
                                if(item.naam == $("#naam").val()){
                                                    if (item.prijs != 
"undefined") {
                                            response.values = item.prijs;
                                                                 
$("#prijs").text(item.prijs);
                                        }
                                                }else{alert("nope code does not 
exist");}
                            });
                            return response;
                        })();
                             $("#prijs").show();
                    });
        });
        berekenTotaal();
});
var jJSON = {
    getValues: function(obj) {
        return jJSON[obj]["values"];
    },
};

</script>

<form action="" method="" accept-charset="utf-8">
<p><input type="text" id="naam" /> <span id="prijs"></span></p>
<p><input type="submit" value="Continue" /></p>
</form> <p><span id="totaal"></span></p>

On Jun 3, 1:14 pm, Charlie <charlie...@gmail.com> wrote:
> you can search the json array with $.each
> var nameWanted = "a";
> var data={"channel":{"items":[{"id":"1","prijs":"10","naam":"a"},
> {"id":"2","prijs":"5","naam":"b"},
> {"id":"3","prijs":"22","naam":"c"}]}}
> $.each(data.channel.items,function(i,item) {
>     if (data.channel.items[i].naam == nameWanted) {
>     index=i;
>         prijsWanted= data.channel.items[i].prijs;
>         alert(prijsWanted);
>        
>     }
> });
> Kristof wrote:i like the idea of building in a treager. each time the user 
> ads a new product or changes a product i could rewrite the new file. Good 
> idea thanks! thanks for the URL"s too ! On Jun 2, 8:02 pm, 
> jsuggs<jsu...@gmail.com>wrote:Look at some of the auto-complete plugins, they 
> do a lot of what you are asking for already including caching of results so 
> that you don't have to do as many lookups or 
> requests.http://plugins.jquery.com/project/autocompletexhttp://plugins.jquery.com/project/js-autocompletehttp://plugins.jquery.com/project/ajax-autocompleteAnd
>  yes, having a process run daily to generate the values can be a good idea if 
> you don't need up-to-date values.  One other method is to have a "trigger" 
> run every time that a new value is added.  That way, when the first item is 
> added the file will be created with just the single item.  You wouldn't have 
> to hit the database again until another item was added and the file 
> overwritten.  Both methods are pretty common practice, but don't overestimate 
> the cost of doing a live database lookup, if you have an index on the column 
> that you are searching through then its impact should be fairly minimal (thus 
> eliminating the need for a more complex solution). On Jun 2, 4:03 am, 
> Kristof<kristofstrooba...@gmail.com>wrote:Hello, i have just joined this 
> group. First Google group i join ! I'm not native English speaking so sorry 
> if i make some grammar mistakes.Anyway, the past 2 weeks i've been looking 
> into JSON/AJAX functions of jquery. Now the reason for me doing that is that 
> I want to make the following:I want to have an input field that ask you for a 
> code, let's say "abc", my script should then automatically search for the 
> price in the database, so with an onblur i suppose.Now i googled/read etc 
> etc, and i came up with a script that worked. It ran a PHP script, generated 
> an array according to the SJON standard that i found on the official 
> website.BUT after re-thinking  what I was doing i thought to myself "what if 
> I have a database with 10 000 products. I would load a query each time to 
> search trough these 10 000 products/items.  So I figured there must be a 
> better way. So i came up with the following idea:lets run the PHP scripts 
> one's a day and generate a .JS file containing ALL the products in some sort 
> of array readable for $.getJson(). And this is where I get stuck: how can I 
> read trough the JS file and only select the price of the item of witch I 
> typed in the code "abc" ?so if I have products.JS generated by PHP-script 
> containing : {"channel":{"items":[{"id":"1","prijs":"10","naam":"a"}, 
> {"id":"2","prijs":"5","naam":"b"}, {"id":"3","prijs":"22","naam":"c"}]}}how 
> could I select the "prijs" of product "a" from that JS-file ? Is it at all 
> possible and if so how ?Help would be greatly appreciated !

Reply via email to