Jump to content

textbox with instant update value?


joecooper

Recommended Posts

Hi,

 

Im trying to add a form where the user can enter how many clicks they wish to purchase for advertising, but with discounts for over 500 clicks.

 

I need them to enter the amount, and instantly would appear the total price (0.01 per click). but 50% discount for over 500..

 

Im pretty much trying to do what this site has at the bottom of the page: http://dailybitcoins.org/ads

 

But looking at the source code i cant find how they are doing it.

 

Thanks

 

Joe

Link to comment
Share on other sites

Without JQuery

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
	function updatePrice( clicks ) {
		var span = document.getElementById('clicksCost');
		if( isNaN(clicks) ) {
			span.innerHTML = 'n/a';
		} else {
			if( +clicks >= 500 ) {
				var cost = +clicks * 0.005
				span.innerHTML = round( cost );
			} else { 
				var cost = +clicks * 0.01;
				span.innerHTML = round( cost )
			}
		}
	}
	function round(n) {
		return Math.round(n*100+((n*1000)%10>4?1:0))/100;
	}
</script>
</head>
<body>
<p><input type="text" id="clicks" onkeyup="updatePrice(this.value)"></p>
<span id="clicksCost">n/a</span>
</body>
</html>

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.

Guest
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.