Solved

JQuery Syntax

Posted on 2015-02-13
9
83 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 32

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 32

Expert Comment

by:Big Monty
ID: 40608619
ok stick that in where item_options is located
0
 
LVL 7

Author Comment

by:rgranlund
ID: 40608635
N, it did not work.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 32

Expert Comment

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

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 32

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now