joecooper Posted September 7, 2011 Share Posted September 7, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/246656-textbox-with-instant-update-value/ Share on other sites More sharing options...
voip03 Posted September 7, 2011 Share Posted September 7, 2011 onclick change value OR you can use jquery Quote Link to comment https://forums.phpfreaks.com/topic/246656-textbox-with-instant-update-value/#findComment-1266585 Share on other sites More sharing options...
dougjohnson Posted September 7, 2011 Share Posted September 7, 2011 Yes I agree. look into javascript and maybe innerHtml. Depending on how you want to display the total price. Quote Link to comment https://forums.phpfreaks.com/topic/246656-textbox-with-instant-update-value/#findComment-1266594 Share on other sites More sharing options...
codefossa Posted September 7, 2011 Share Posted September 7, 2011 Check out the keydown() function, and just take the values and update wherever you wanna show the total. http://api.jquery.com/keydown/ Like the said, you will need to use Javascript to do it, and I would suggest JQuery, but you can use plain Javascript if you really want to. Quote Link to comment https://forums.phpfreaks.com/topic/246656-textbox-with-instant-update-value/#findComment-1266603 Share on other sites More sharing options...
xyph Posted September 7, 2011 Share Posted September 7, 2011 For something this simple, using an entire framework like JQuery seems overkill. Just my opinion. Quote Link to comment https://forums.phpfreaks.com/topic/246656-textbox-with-instant-update-value/#findComment-1266606 Share on other sites More sharing options...
joecooper Posted September 8, 2011 Author Share Posted September 8, 2011 ah thanks. I would be using jquery sometime in the future when I get used to it a bit more. but for now I just require a simple script to display the total cost as the user types. that way they can quickly check how much they can buy with their balance. Quote Link to comment https://forums.phpfreaks.com/topic/246656-textbox-with-instant-update-value/#findComment-1267008 Share on other sites More sharing options...
xyph Posted September 8, 2011 Share Posted September 8, 2011 Are you asking for help here? Or telling us you've found a solution? Quote Link to comment https://forums.phpfreaks.com/topic/246656-textbox-with-instant-update-value/#findComment-1267046 Share on other sites More sharing options...
joecooper Posted September 8, 2011 Author Share Posted September 8, 2011 help at the moment, this is the last thing i need to do for my new website. going to have a little look into it, but its a must before it goes live Quote Link to comment https://forums.phpfreaks.com/topic/246656-textbox-with-instant-update-value/#findComment-1267065 Share on other sites More sharing options...
joecooper Posted September 8, 2011 Author Share Posted September 8, 2011 <script type="text/javascript"> function clickstotal() { $('clickscost').innerHTML = $('clicks').value * 0.05; } </script> This doesnt seem to work. textfeild is called clicks. clickscost is the DIV. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/246656-textbox-with-instant-update-value/#findComment-1267081 Share on other sites More sharing options...
Adam Posted September 9, 2011 Share Posted September 9, 2011 With jQuery objects you need to use the val() and html() methods: $('clickscost').html($('clicks').val() * 0.05); Quote Link to comment https://forums.phpfreaks.com/topic/246656-textbox-with-instant-update-value/#findComment-1267277 Share on other sites More sharing options...
xyph Posted September 9, 2011 Share Posted September 9, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/246656-textbox-with-instant-update-value/#findComment-1267435 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.