3 Replies - 4422 Views - Last Post: 05 April 2013 - 04:10 PM

#1 skyerz   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 211
  • Joined: 14-October 10

With Jquery make a shopping cart from json array

Posted 05 April 2013 - 09:14 AM

Ive found a fancy shopping cart tutorital which gives a decent break down of how to do it step by step, i followed pretty well until i got up to a line of code which i dont under stand
(function($){	
	    $.fn.smartCart = function(options) {  	
        var options = $.extend({}, $.fn.smartCart.defaults, options);
                
        return this.each(function() {
        	
                var obj = $(this);
                // retrive all products
                var url = "shoppingItems.json";//essentially new products
                var products = $("input[type=hidden]",obj);//what is this for
}); 
    };
})( jQuery );

The code which im not sure about is var products =$("input[type = hidden]",obj); From what i understand, this is a multiple selector which is being put into products, which i cant see a use of. obj is simply a empty div tag in whihc i call from my html
<script type="text/javascript">
   
    $(document).ready(function(){
    	// Call Smart Cart instead of features maybe something more higher up to include more features    	
  		$('#featured').smartCart();
		});
</script>

the <input> is comprised of a list of shopping items which i have now moved into json file(so i will soon not be needing to use input rather my json url)
Essentially i would like to know if var products is a multiple selector, and if so why. understanding this will make the transition to making it json rather than from html easier.

Is This A Good Question/Topic? 0
  • +

Replies To: With Jquery make a shopping cart from json array

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: With Jquery make a shopping cart from json array

Posted 05 April 2013 - 09:21 AM

View Postskyerz, on 05 April 2013 - 05:14 PM, said:

var products = $("input[type=hidden]",obj);//what is this for

cf. http://api.jquery.com/jQuery/. search for hidden form fields in obj. (similar to document.getElementById("x").getElementsByTagName("y"))
Was This Post Helpful? 1
  • +
  • -

#3 skyerz   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 211
  • Joined: 14-October 10

Re: With Jquery make a shopping cart from json array

Posted 05 April 2013 - 09:51 AM

so find elements within
<input>
that are also inside obj??? in that case by taking obj out it shouldnt really effect anything more just the search results ?

This post has been edited by skyerz: 05 April 2013 - 03:37 PM

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: With Jquery make a shopping cart from json array

Posted 05 April 2013 - 04:10 PM

and what if you have hidden input fields elsewhere in your page that do not belong to the smartCart?

PS. obj == $("#featured")

This post has been edited by Dormilich: 05 April 2013 - 04:12 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1