• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 95
  • Last Modified:

JQuery Syntax

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
rgranlund
Asked:
rgranlund
  • 5
  • 4
1 Solution
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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
 
rgranlundAuthor Commented:
The full name of the select in the HTML is "item_options[product_deductible"
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
ok stick that in where item_options is located
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rgranlundAuthor Commented:
N, it did not work.
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
what's the full html for the select box?
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
better yet, do you have a link to the page?
0
 
rgranlundAuthor Commented:
http://23.101.151.179/index.php?/store/29

Change the "Select My Deductible"
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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
 
rgranlundAuthor Commented:
I literally just figured that out!!!!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now