JSFiddle - React, Tailwind, and code Playground

by master1991

HTML

<label>Hours, Dec</label>
<input type="text" id="a" >

<label>Duration</label>
<input type="text" id="b" >

JavaScript

function a(){

	var a = $('#a').val();
  
  
  //$('#b').val(((parseFloat(a)*60).toFixed(10)*1/1));
  
  
  var SecondsTohhmmss = function(totalSeconds) {
    var hours   = Math.floor(totalSeconds / 3600);
    var minutes = Math.floor((totalSeconds - (hours * 3600)) / 60);

    var result = (hours != 0 ? hours + "h" : "");
        result += (minutes != 0 && hours != 0 ? " " : "");
        result += (minutes != 0 ? minutes + "m" : "");
    return result;
  }

  // example
  seconds = ((parseFloat(a)*3600).toFixed(10)*1/1);
  var seconds1 = SecondsTohhmmss(seconds);  
  $('#b').val(seconds1);
  

}

$('#a').on('keyup blur', a);



function b(){

	var b = $('#b').val();
  $('#a').css("background-color", "white");
  if (b.indexOf('h') == -1 && b.indexOf('m') == -1){
  	val = ((parseFloat(b)/60).toFixed(10)*1/1);
  	
    if(!isNaN(val)){
    	$('#a').val( Math.round(val * 100) / 100 );
    }else{
    	$('#a').val('0');
    }
    
    if (/\s/.test(val)) {
     $('#a').css("background-color", "red");
    } 
    console.log('LVL 1');
    
  }
  
  if (b.indexOf('h') > -1 && b.indexOf('m') == -1){
  	val = b.replace("h", "");
    
    if(!isNaN(val)){
  		$('#a').val( Math.round(val * 100) / 100 );
    }else{
    	$('#a').val('0');
    }
    
    if (/\s/.test(val)) {
     $('#a').css("background-color", "red");
    } 
    console.log('LVL 2');
    
  } 
  
  if (b.indexOf('h') == -1 && b.indexOf('m') > -1){
    val1 = b.replace("m", "");
  	val =  ((parseFloat(val1)/60).toFixed(10)*1/1) ;
  	
    if(!isNaN(val)){
    	$('#a').val( Math.round(val * 100) / 100 );
    }else{
    	$('#a').val('0');
    }
    
    if (/\s/.test(val)) {
     $('#a').css("background-color", "red");
    }    
    console.log('LVL 3');
    
  }  

  if (b.indexOf('h') > -1 && b.indexOf('m') > -1){
  	c = b.replace("h", "");
    d = c.replace("m", "");
    
		h = d.substr(0,d.indexOf(' '));
    h = parseInt(h.trim());
		m = d.substr(d.indexOf(' ')+1);  
    m = parseInt(m.trim());
    m =...