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
Solved

JQuery Syntax

Posted on 2015-02-13
9
88 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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to count the days a record spends in a step 21 49
Optimize the query 5 43
how to double quote a string for an inline sql statement. 8 73
Html Newline 7 20
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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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)

840 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