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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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> Quote Link to comment 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! Quote Link to comment 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.