Shamrox Posted April 20, 2007 Share Posted April 20, 2007 I have a dropdown list on a form that lists different types of credit cards. I also have a form field that is called charge card fee and I would like this to be populated with a $ amount based on what card was selected from the dropdown. Each card has a different fee that is a % of the sale price. So there is a third field of Price that is involved. Is there a way to have the fee field calculated and populated using javascript? Any help is appreciated. Thanks. Link to comment https://forums.phpfreaks.com/topic/47921-solved-possible-with-javascript/ Share on other sites More sharing options...
fenway Posted April 20, 2007 Share Posted April 20, 2007 Sure, onchange of the dropdown, call a JS function that checks a hash of CC options and contains the % fee; then pull the price, and update the fee field appropriately Link to comment https://forums.phpfreaks.com/topic/47921-solved-possible-with-javascript/#findComment-234199 Share on other sites More sharing options...
Shamrox Posted April 20, 2007 Author Share Posted April 20, 2007 Could you provide a bit of code example as I have no clue how to write js. Link to comment https://forums.phpfreaks.com/topic/47921-solved-possible-with-javascript/#findComment-234208 Share on other sites More sharing options...
emehrkay Posted April 22, 2007 Share Posted April 22, 2007 function checkCC(){ var type = document.getElementById(this); var perct = 0; switch(type){ case 'visa': perct = .25; break; case 'mastercard': perct = . 28; break; } document.getElementById('id of field that holds the percent value, this could be a hidden field, just give it an id').value = perct; } <select onchange = "checkCC(this)"></select> Link to comment https://forums.phpfreaks.com/topic/47921-solved-possible-with-javascript/#findComment-235532 Share on other sites More sharing options...
Shamrox Posted April 24, 2007 Author Share Posted April 24, 2007 Thanks emehrkay, that was a ton of help! Link to comment https://forums.phpfreaks.com/topic/47921-solved-possible-with-javascript/#findComment-236539 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.