Solved

JQuery Syntax

Posted on 2015-02-13
9
87 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
  • 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
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.

 
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 500 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

786 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