javascript - Combine 2 scripts -
i have these 2 scripts cant set them work together
function start() { var f=document.getelementbyid("hipaya"); var s=document.getelementbyid("paypala"); var l=document.getelementbyid("skrilla"); f.style.display = 'block'; s.style.display = 'none'; l.style.display = 'none'; } function disp_div() { var word = document.myform.mycred_buy.selectedindex; var selected_text = document.myform.mycred_buy.options[word].text; var f=document.getelementbyid("hipaya"); var s=document.getelementbyid("paypala"); var l=document.getelementbyid("skrilla"); if (selected_text == 'hipay'){ f.style.display = 'block'; s.style.display = 'none'; l.style.display = 'none'; }else if (selected_text == 'paypal ou cartão crédito/débito'){ f.style.display = 'none'; s.style.display = 'block'; l.style.display = 'none'; }else if (selected_text == "skrill (moneybookers)"){ f.style.display = 'none'; s.style.display = 'none'; l.style.display = 'block'; } } window.onload = function() { var calculsumtostring = function calculsumtostring() { totalfield.value = (qtyfield.value * 0.1).tofixed(2) + " €"; }; var totalfield = document.getelementbyid('total_price'); var qtyfield = document.getelementbyid('amount'); qtyfield.onkeyup = calculsumtostring; itempricefield.onkeyup = calculsumtostring; };
does 1 have thought why cant set together? 1 works. if set 1st 1 last, works sec stops workin
because itempricefield
undefined (i presume old name variable).
i presume line:
itempricefield.onkeyup = calculsumtostring;
should be:
totalfield.onkeyup = calculsumtostring;
additionally, function definition calculsumtostring
incorrect, should be:
var calculsumtostring = function() { totalfield.value = (qtyfield.value * 0.1).tofixed(2) + " €"; };
as why javascript not work @ when order other way around because function evaluation stop on first error (when trying access property of undefined
or wrong function syntax).
jslinters can pick issue , can included part of bundling , minification step - i'd recommend having quick google around these areas if you're interested in creating robust javasscript (in add-on unit test frameworks js).
javascript
No comments:
Post a Comment