Jump to content

Select value from array


Recommended Posts

Hello there friends


I have an select box and I would like to define the alue of the selects with array. Like this:

 var price_list= new Array();

The I have a Selectbox where

<form action="" id="metal" onsubmit="return false;"
            <select id="a" name="metals" class="form-select">
                    <option value="-">-</option>
                    <option value="bronze">bronze</option>
                    <option value="silver">silver</option>
                    <option value="gold">gold</option>

And performig calculations with following script (that works fine if the value is directly in select). And obviously there is another select (#b) but that is just numbers so I didn show it here.

  $(document).ready(function() {
           function compute() {
              var a = $('#metals').val();
              var b = $('#b').val();
              var total = a * b * 1.22;

            $('#metals, #b').change(compute);

I just get returned NaN

If you have an answer then please hit

Link to comment
Share on other sites

The value of that metals thing is the value of the selected option. So "-" or "bronze" or "silver" or "gold".


If you want the value to be a number then make the value be a number.

<option value="0">-</option>
<option value="5">bronze</option>
<option value="10">silver</option>
<option value="15">gold</option>
Link to comment
Share on other sites

You get the values from AJAX and then put them into the


Whatever the method is, you do have both the label and the value so you should be producing list items like

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.