+ 1
set value in input from 3 different variables?
Any way to set value in input from different variables? Somethin' like this,but this one doesn't work :D $('#result').val(a operation b); Prefer JS or JQ solutions. Code: https://code.sololearn.com/W3X8ygh7Dt5K/#js
6 Antworten
+ 7
For your reference.
http://stackoverflow.com/questions/5834318/are-variable-operators-possible
+ 5
var a = 5;
var b = 10;
document.getElementById('result').setAttribute('value',a*b);
This works. You can have operation also as a variable.
+ 5
@Rose I think you need to use switch on the operation variable with different cases to work with different operations. I doubt if providing directly an operation as a string variable will work.
+ 1
$('#result').val(a*b);
document.getElementById('result').setAttribute('value',a*b);
Both of them works same way...but when I try to use "operation" variable with + or - or / or * from selected option it doesn't work.
+ 1
You can check full code here ,also moved to question header.
https://code.sololearn.com/W3X8ygh7Dt5K/#js
Yeah...I thought about different operation with different conditions...
If selected option + {$('#result').val(a+b);}
e.t.c but...I still hope here's other way with just changing (arguments) :D
Operation variable is string type,checked it too.
+ 1
Yep...that's the way too,thank you.
Not that cool,but seems like only possible :)