?
Solved

JQuery Syntax

Posted on 2015-02-13
9
Medium Priority
?
91 Views
Last Modified: 2015-02-13
I am having trouble writing the following JQuery.  I want to grab the value of a select field option, by it's name.  Then I want to insert that value into a html div ID.  I want to do this, call the function when on select change.

<script>
function total() {
         
 var deductible = $( 'name="item_options[product_deductible]"' ).val();
 
  $( "#result" ).innerHTML( deductible );
 }

 $( "select" ).change( total );
 total();
 
</script>

Open in new window

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
  • 5
  • 4
9 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 40608490
try this:

$('select[name="item_options"]').change(function() {
  $( "#result" ).html( $(this).val() );
});

Open in new window


this assumes your select box is named item_options
0
 
LVL 7

Author Comment

by:rgranlund
ID: 40608612
The full name of the select in the HTML is "item_options[product_deductible"
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40608619
ok stick that in where item_options is located
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 7

Author Comment

by:rgranlund
ID: 40608635
N, it did not work.
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40608646
what's the full html for the select box?
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40608648
better yet, do you have a link to the page?
0
 
LVL 7

Author Comment

by:rgranlund
ID: 40608681
http://23.101.151.179/index.php?/store/29

Change the "Select My Deductible"
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 2000 total points
ID: 40608710
your first problem is the code is before you load jquery, so it doesn't recognize the jquery reference.  put the following code block after you load jquery:

<script>
$( document ).ready(function( $ ){
   $('select[name="item_options[0][product_deductible]"]').change(function() {
       $( "#result" ).html( $(this).val() );
   });
});
</script>

Open in new window


any reason why you can't reference it by ID?
0
 
LVL 7

Author Closing Comment

by:rgranlund
ID: 40608728
I literally just figured that out!!!!
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

752 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