Hi all, looking for a little bit of advice. I’m more of a PHP man myself but see that a lot of Javascript is relatively similar. I’m working on creating an online shop - basically I have a few products that have different sizes and for each size there is a different price. I have a dropdown list, for example:
Small (£25.00)
Medium (£30.00)
Large (£35.00)
Now by default the first size is shown. If a user clicks on a different size, I want the price to change in the main product price div. How can this be done?
So basically want I want is: if there is an option that has brackets, then strip the brackets and show what’s inside them in the main price DIV.
Any help is appreciated as always!
A regular expression would probably be the easiest way to do that.
If this will be in a select drop down, why not put the dollar amount in the value attribute?
example:
<option value=“£25.00”>Small (£25.00)</option>
Here is a quick test using jQuery:
<!doctype html>
<html>
<head>
<title></title>
<style></style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script></script>
</head>
<body>
<form>
<select name="selectItem">
<option value="£25.00" selected="selected">Small (£25.00)</option>
<option value="£30.00">Medium (£30.00)</option>
<option value="£35.00">Large (£35.00)</option>
</select>
<div id="price"></div>
</form>
<script>
$(document).ready(function() {
$('select[name="selectItem"]').change(function() {
var value = $('select[name="selectItem"] option:selected').val();
$('#price').text(value);
}).trigger('change');
});
</script>
</body>
</html>
Hey dude, I need the value of the option as when a user chooses the option, the value is then compared to that in the database and gets the price, hence why if I could get the figure between the brackets then update the price DIV.