Solved

JQuery Syntax

Posted on 2015-02-14
3
77 Views
Last Modified: 2015-02-14
I am trying to grab the Dta Value from a specific select option:
<script>
 				var usage_sel = $('select[name="item_options[usage]"]').attr('data-damage');
 				var usage_var = usage_sel.data('damage'); 		
 			
 				if ( usage_var == null  ) {
 					usage = 1;
 				} else if ( usage_var == undefined ) {
 					usage = 1;
 				} else {
 					usage = usage_var;
 				}	
 				alert(usage);	
</script>

Open in new window

The select name is item_options[usage]
the data is data-damage

What am I doing wrong?
0
Comment
Question by:rgranlund
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 total points
ID: 40610255
var usage_sel = $('select[name="item_options[usage]"]').attr('data-damage');
                         
should be

var usage_sel = $('select[name="item_options[usage]"]').data('damage');
0
 
LVL 7

Author Comment

by:rgranlund
ID: 40610287
When I do this: var usage_sel = $('select[name="item_options[usage]"]').data('damage');   I have it to alert on change and I get undefined.  Do I need to add more to it to get the DATA value from the selected option?
0
 
LVL 7

Author Closing Comment

by:rgranlund
ID: 40610293
I had to do the following: var usage_sel = $('select[name="item_options[usage]"]').find(':selected').data('damage');
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

929 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now