SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Update Variable On SELECT Box Choice

    Greetings,

    I need to simply add a dollar (Set price to $16 instead of $15) if the user selects XXL.

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>t-shirt Order</title>
    <link rel="stylesheet" href="css/styles.css" type="text/css" media="all" />
    <script language="JavaScript">
    
    var price = "$15.00"
    
    function getOptionValue()
     	{
     		var price = "$15.00";
     		
     		if(document.form.size.value == "XXL") {
     		
     		var price = "$16.00";
     		
     		} 
     	}
    </script>
    </head>
    
    <body>
    <div id="main">
      
    <div id="content"> <img src="images/tshirt-lines_circles.gif" width="800" height="395" border="0" /><br><br>
    <center><strong><script type="text/javascript">document.write(price);</script></strong>
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="form" target="_blank">
    <input type="hidden" name="add" value="1">
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="business" value="xxxx">
    <input type="hidden" name="undefined_quantity" value="1">
    <input type="hidden" name="item_name" value="Shirt">
    <input type="hidden" name="item_number" value="xxxxx">
    <input type="hidden" name="amount" value="15.00">
    <input type="hidden" name="page_style" value="PayPal">
    <input type="hidden" name="no_shipping" value="2">
    <input type="hidden" name="return" value="http://www.xxx.com/thanks.php">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="lc" value="US">
    <input type="hidden" name="bn" value="PP-BuyNowBF">
    <input type="hidden" name="on0" value="Size">Size
    
    	<select name="size" onchange="getOptionValue();">
    		<option value="Medium">Medium</option>
    		<option value="Large">Large</option>
    		<option value="XL">XL</option>
    		<option value="XXL">XXL</option>
    	</select>
    
    <br><br>
    <input type="image" src="images/buyit.gif" border="0" width="126" height="23" name="submit" alt="Click here to Buy!"> 
    </form></center>
    </div>
    </div>
    </body>
    </html>
    I've googled and searched here and can't find a clear-cut example.

    Thanks

  2. #2
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script type="text/javascript">
    function removeText(what){
    var what=document.getElementById(what);
    whatChild=what.removeChild(what.childNodes[0]);
    }
    function txt(what,hlaska){
    removeText(what);
    var newText=document.createTextNode(hlaska);
    document.getElementById(what).appendChild(newText);
    }
    function changeDiv(){
    document.getElementById('size').onchange=function(){
    if(this.options[this.selectedIndex].value=='XXL'){
    txt('price','$16.00')
    }
    else{txt('price','$15.00')}
    }
    }
    window.onload=changeDiv
    </script>
    <strong id="price">$15.00</strong>
    <select name="size" id="size">
    <option value="Medium">Medium</option>
    <option value="Large">Large</option>
    <option value="XL">XL</option>
    <option value="XXL">XXL</option>
    </select>


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
  •