views:

35

answers:

1

Hello,

I have a input field in which users specify file size in Mb, so for gb they have to calculate right now.

I want to change the input fields value automatically in calculated Mbs if users type gb after the number.

Example: 1024mb = 1gb

So if a user types 5gb in input field jquery takes the value onchange and updates the fields value after calculating it which would be 5 * 1024 = 5120 in this case.

Thank You

+2  A: 
$('#fileSize').change(function(){
var sz = $(this).val().match(/(\d+)gb/i);
if(sz.length > 1){
  $(this).val(parseInt(sz[1])*1024);
}
});
prodigitalson