jquery parseFloat assigning val to field

Posted by user306472 on Stack Overflow See other posts from Stack Overflow or by user306472
Published on 2010-04-19T23:08:17Z Indexed on 2010/04/19 23:13 UTC
Read the original article Hit count: 1304

Filed under:
|
|

I have a select box that gives a description of a product along with a price. Depending on what the user selects, I'd like to automatically grab that dollar amount from the option selected and assign it to a price input field. My HTML:

<tr>
    <td>
        <select class="selector">
            <option value="Item One $500">Item One $500</option>
            <option value="Item Two $400">Item Two $400</option>
        </select>
    </td>
    <td>
        <input type="text" class="price"></input>
    </td>
</tr>

So based on what is selected, I want either 500 or 400 assigned to the .class input. I tried this but I'm not quite sure where I'm going wrong:

$('.selector').blur(function(){
    var selectVal = ('.selector > option.val()');
    var parsedPrice = parseFloat(selectVal.val());
    $('.price').val(parsedPrice);
});

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about parsefloat