Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6145161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:45:22+00:00 2026-05-23T18:45:22+00:00

I needed some help updating the price on a page based on a dropdown

  • 0

I needed some help updating the price on a page based on a dropdown selection.

This is what code with some help we came up with:

    var price = new Array('','$2.00','$45.00','$60.00');
    $(function(){
        $('select[name=material]').change(function(){
          document.getElementById('pprice').innerHTML = price[$(this).val()];
        }); 

        // Trigger on dom ready
        $('select[name=material]').change();
    });

Which works if my dropdown is structured like this:

    <select name="material">
        <option value="">-- Please Select --</option>
        <option value="1">Wood</option>
        <option value="2">Plastic</option>
        <option value="3">Metal</option>
    </select>

But if for any reason the the dropdown was to be like this:

    <select name="material">
        <option value="">-- Please Select --</option>
        <option value="3">Metal</option>
        <option value="4">Cloth</option>
        <option value="5">UPVC</option>
    </select>

it would not work (because the value option is not 1,2,3). The value is the id for the material. Hope this makes sense and that someone can help me to get this working.

Thanks
Dino

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:45:23+00:00Added an answer on May 23, 2026 at 6:45 pm

    Just select price using the selectedIndex of your <select>:

    var price = new Array('','$2.00','$45.00','$60.00');
    $(function(){
        $('select[name=material]').change(function(){
            document.getElementById('pprice').innerHTML = price[this.selectedIndex];
        });
    
        // Trigger on dom ready
        $('select[name=material]').change();
    });
    

    Or, use an object instead of an array for price:

    var price = {
        "4": "$2.00",
        "5": "$45.00",
        "6": "$60.00"
    };
    $(function(){
        $('select[name=material]').change(function(){
            document.getElementById('pprice').innerHTML = price[$(this).val()];
        });
    
        // Trigger on dom ready
        $('select[name=material]').change();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I needed some help in trying to optimize this code portion ... Basically here's
I am very new to WPF and needed some pointers as to why this
I am new to Flex and needed some help setting up Web service client.
Hey guys! I need some help writing a code that creates an array in
I am new to using the printdocument feature in c# and needed some help.
I made this and needed some help tweaking it so that it gives the
What's up guys! I gonna need some help! Inside of this code return ControllTheDog(D,
Some MATLAB help needed ! I have an set of 1s and 0s, I
I needed some simple string encryption, so I wrote the following code (with a
I needed some help/pointers on a homework problem. I would really appreciate it if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.