简体   繁体   中英

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. 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? Ideally, I need 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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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