Solved

JQuery Syntax

Posted on 2015-02-14
3
81 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
[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
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
Rob 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
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…

705 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