As the count value depending on the selected unit?

There are 3 fields, width and height select the unit of measurement( mm, cm, m)
as in the changes unit. to change the values in width and height? (to adjust the size of the exposed).
mathematics understandable, but I do not understand how the script to explain what the unit replaceable?
if mm is in cm / mm from 10 to m /1000, and so on....
March 19th 20 at 08:40
1 answer
March 19th 20 at 08:42
Solution
all gratuiti in millimeters, and with display type

shirina = 1000 // in the script of the stored value in mm, 1000 mm

if (selected == "metr") {
 shirinaKotorujuPishemNaSajte = shirina / 1000 // in meter 1000 mm
}
okay, but shirinaKotorujuPishemNaSajte it changes, for example from the cm turned it into a m
and when turned into mm, we take from the field shirinaKotorujuPishemNaSajte and its multiply/divide?

my default is cm width=100
$('#width').val() // 100 - Stefan commented on March 19th 20 at 08:45
well, I meant so
https://codepen.io/anon/pen/ZPZmao
but for another input, to hang a listener that when changing the numbers in the input will also look at the value of the select, and translate in mm

upd:
https://codepen.io/anon/pen/ZPZmao - marcel commented on March 19th 20 at 08:48
@marcel, so sorry, I copy this code I have all the errors what's missing? I have only Juqery connected - Stefan commented on March 19th 20 at 08:51
@Stefan, there is even no jquery :)
what error writes?
in codepen it works, right? - marcel commented on March 19th 20 at 08:54
@marcel, Uncaught TypeError: Cannot read property 'addEventListener' of null - Stefan commented on March 19th 20 at 08:57
in PHP storm editor, it's all red, supposedly code invalid - Stefan commented on March 19th 20 at 09:00
Uncaught TypeError: Cannot read property 'addEventListener' of null
well, it's probably because the members of another id, different from my input id="w" value="500"

about phpstorm don't know, because it should work :) - marcel commented on March 19th 20 at 09:03
Plz help with my code to connect, I have input and select run one function
'onchange' => 'getData()'
below the function itself
$sz = $("#wide-selectsize").val(); // here the id of the selected unit (0=mm, 1=cm, 2=meter)
$width = $('#wide-width').val(); // input field width

 if($sz == 0) {
 $('#wide-width').val($width *10);
}
 if($sz == 1) {
 $('#wide-width').val($width / 10); 
}
 if($sz == 2) {
 $('#wide-width').val($width / 100);
 }

it works until the meters will switch off, then gets off and says is not right, you have here the second listener, I don't know how to stick it here - Stefan commented on March 19th 20 at 09:06
@Stefan, Oh well, it's hard to say immediately the piece to the end of working code on the same codepen?

the idea is that listening to a change on input
$('#wide-width').on('change', function() {
 val = $("#wide-selectsize").val(); // here the selected unit id (1=mm, 2=cm, 3=meter)

 // and then like me
 if(val == 1) {
 // mm -> cm
 $('#wide-width').val($width* 10);
 } else if (val == 2) {
 // cm -> cm is nothing to translate
 $('#wide-width').val($width); 
 } else if (val == 3) {
 // m-> cm
 $('#wide-width').val($width / 100);
}
})

and here already can be mistakes, I'm not very jquery - marcel commented on March 19th 20 at 09:09
no, not running your code on codepen to make the default width of 100, and stood to see ? I'm undone, and I the first change does not change anything, then %\ - Stefan commented on March 19th 20 at 09:12
put on the default 100 and cm changed to mm and nothing changes - Stefan commented on March 19th 20 at 09:15
phew..I kind polyclose )) was rewritten by jquery - Stefan commented on March 19th 20 at 09:18
@Stefan,
then like so
https://codepen.io/anon/pen/pYBXve

Yes, there is not difficult, only these toe round-trip transfer :D
so for me it is better to store in the smallest unit that is in mm, so in one place only to multiply, and in another place just to share - marcel commented on March 19th 20 at 09:21
no, too happy, if the hands change to 10 starts distorting to believe me, all due to the fact that initially I should SEE! - Stefan commented on March 19th 20 at 09:24
@marcel, thanks, I'll try to rewrite - Stefan commented on March 19th 20 at 09:27

Find more questions by tags jQueryJavaScript