简体   繁体   English

如何将单选按钮的值乘以Javascript中的数字,并在文本区域内的文本字符串中显示答案?

[英]How can I multiply a value from a radio button by a number in Javascript and have the answer display in a textstring inside a textarea?

I need to have the user_input from the radio button multiplied by an integer. 我需要将单选按钮的user_input乘以一个整数。 The user_input is either 1,2, or 3. I can get the radio button value pulled through into the textarea, but how do I take that number and multiply it by something? user_input可以是1,2或3。我可以将单选按钮的值拖入textarea,但是如何将其乘以某个值呢? Ideally, I need textstring += 'Fee (£): ' + (user_input) * '5' + '\\n'; 理想情况下,我需要textstring + ='Fee(£):'+(user_input)*'5'+'\\ n';

Thanks for any help! 谢谢你的帮助!

        // Get value of the 'Fee' radio buttons.

user_input = '';
for (i=0;i<document.forms['example'].fee.length;i++) {
    if (document.forms['example'].fee[i].checked) {
        user_input = document.forms['example'].fee[i].value;
    }
}
textstring += 'Fee (&#163;): ' + user_input + '\n';



// Write textstring to the textarea.

document.forms['example'].output.value = ("\n*** Thank You for your reservation***"+"\n")+ textstring + ("\n*** End of Form***"+"\n");

你有没有尝试过:

textstring += 'Fee (&#163;): ' + (user_input*5) + '\n';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM