How to convert radio group value into number

Converting RadioGroup value (String) to Number
I’m trying to calculate a total from the user selecting an option from a radio button and multiplying it against another field. I’ve converted the string into a number but I keep getting NaN as the result. Please help

export function total_click(event) {
let mealPrep = Number($w( ‘#radioGroup2’ ).value);
let orderAmount = Number($w( ‘#orderAmount’ ));
$w( ‘#totalAmount’ ).text = (mealPrep*orderAmount).toString();

console.log(mealPrep.valueOf()); 

}

@sonyasdivinecreation One thing that catches my eye is that you didn’t add the value property to the orderAmount variable assignment. You would get NaN as the result of the orderAmount calculation because of that.

let orderAmount = Number($w('#orderAmount').value);

I tried this and it still printed out “NaN”

@sonyasdivinecreation Post your Site URL. And the WHOLE code after applying the changes @anthonyb mentioned

@certified-code

export function orders_change(event) {
let mealPrep = Number($w( ’ #radioGroup2 ’ ).value);
let amount = Number($w( ’ #orders ’ ).value);
$w( ’ #total ’ ).text = (mealPrep * amount).toString();
}

URL: https://www.sonyasdivinecreations.com/basic-01

I tried logging the mealPrep value and it returned NaN, so I dont think I’m converting the radio button selection right

@sonyasdivinecreation What are the values that you entered in the Manage Choices dialog?

No matter which radio button I select and whatever number for the amount of orders, it returns NaN.

@sonyasdivinecreation
Can you show your current code?

@russian-dima
export function orders_change(event) {
let mealPrep = Number($w( ’ #radioGroup2 ’ ).value);
let amount = Number($w( ’ #orders ’ ).value);
$w( ’ #total ’ ).text = (mealPrep * amount).toString();
}

@sonyasdivinecreation Taking nothing for granted, you need to see which one of these (or both) is returning NaN. Try this and take a look at the console at the bottom:

export function orders_change(event) { 
 let mealPrep = Number($w('#radioGroup2').value);  
 console.log("mealPrep:",mealPrep);
 let amount = Number($w('#orders').value);      
 console.log("amount:",amount);
 $w('#total').text = (mealPrep * amount).toString(); 
}

@tony-brunsman thanks for your help, I really appreciate it.

after trying this, its definitely mealPrep returning NaN. How can I convert this to a number

@sonyasdivinecreation For the sake of simplicity, I added one of the template radio groups to a page, named it “radiogroup2” and changed the value properties to how I understand that you’ve done it. Your code works in this simple example, meaning the number function did convert the character numeric value of the radio group to a number and stores it in the mealPrep variable. Here is a screen shot of how the “Manage Choices” dialog is set up: