Solved

JQuery Syntax

Posted on 2015-02-13
9
90 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

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

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…

728 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