• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 102
  • 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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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