SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    If in Brackets Redisplay Price

    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!

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    A regular expression would probably be the easiest way to do that.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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:
    Code HTML4Strict:
    <!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>

  4. #4
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •