Solved

JQuery Syntax

Posted on 2015-02-14
3
78 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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…

770 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