User number input, calc, then output (solved)

I have a simple bit of code that should multiply any number the user inputs by a number and then ouput the new amount in a textbox but I can’t seem to get it to work. Any advice…?

$w.onReady(function() {
$w(‘#input1’).onChange(function(){
$w(‘#text1’).valueOf($w(‘#input1’).value * 1.5);
});
});

Hey,
You can parse a string to a number using the following methods:

Best,
Tal.

1 Like

Solution:

$w.onReady(function(){
var b = ‘3’;

$w("#input1").onKeyPress(function(){ 
$w("#text1").text = String(parseFloat($w("#input1").value) * b); 

});
});

2 Likes

Hi,

Thanks for this example, as this is very close to my requirement. However, i also need an if function to check conditions before multiplying and showing in text box.
It works without the if function. The if conditions are somehow not getting checked. Kindly advise on below:

export function fastGo_click_1(event) {
//Add your code for this event here:
var r1 = 40;
var r2 = 50;
var r3 = 60;

if (("#fastInput").value < 10) { 
	$w("#fastCost").text = String(parseInt($w("#fastInput").value)*1); 
	$w("#fastyCost").text = String(parseInt($w("#fastInput").value)*1*12); 
	} 

if (("#fastInput").value >= 10 && ("#fastInput").value < 50) { 
	$w("#fastCost").text = String(parseInt($w("#fastInput").value)*r2); 
	$w("#fastyCost").text = String(parseInt($w("#fastInput").value)*r2*12); 
	} 

if (("#fastInput").value >= 50) { 
	$w("#fastCost").text = String(parseInt($w("#fastInput").value)*r3); 
	$w("#fastyCost").text = String(parseInt($w("#fastInput").value)*r3*12); 
            } 

}

Hi Varun

Apologies for the late reply, I must have missed the notifcation that came through on my email.

I’m still pretty inexperienced myself, but perhaps try placing an }else if{ between the options as below:

if ((“#fastInput”).value < 10) {
$w(“#fastCost”).text = String(parseInt($w(“#fastInput”).value)*1);
$w(“#fastyCost”).text = String(parseInt($w(“#fastInput”).value)112);
}else if{
((“#fastInput”).value >= 10 && (“#fastInput”).value < 50) {
$w(“#fastCost”).text = String(parseInt($w(“#fastInput”).value)*r2);
$w(“#fastyCost”).text = String(parseInt($w(“#fastInput”).value)r212);
}else if{
((“#fastInput”).value >= 50) {
$w(“#fastCost”).text = String(parseInt($w(“#fastInput”).value)*r3);
$w(“#fastyCost”).text = String(parseInt($w(“#fastInput”).value)r312);
}

1 Like

Hi Tiaan,

Thanks for the response. However, i resolved the issue by inserting $w in “if” conditions:
if ( $w (“#fastInput”).value < 10)