Please help, result not displayed.. Javascript

This is my updated code… but my results is not been displayed in the results box… help

Scale Balancing
		Number 1: <input type="text" name="txtnum1">
		<br>
		Number 2: <input type="text" name="txtnum2">
		<br>
		Result : <input type="text" name="txtres"><br>
		
		<input type="button" value="Calculate" onClick="pushData()">
		
	</form>
	
	<script type="text/javascript">
			
			function pushData()
			{
			var w1, w2, res;
			var weights = [1, 2, 7, 7];
			w1=Number(document.scalebalancing.txtnum1.value);
			w2=Number(document.scalebalancing.txtnum2.value);
			
			for (var i = 0; i < weights.length; i++) {
			if (w1 + weights[i] === w2 || w2 + weights[i] === w1) { return '' + weights[i]; }
			for (var j = i + 1; j < weights.length; j++) {
			if (w1 + weights[i] + weights[j] === w2 || w2 + weights[i] + weights[j] === w1 || w1 + weights[i] === w2 + weights[j] || w2 + weights[i] === w1 + weights[j]) {
			return '' + weights[i] + ',' + weights[j];

			}
		}		
	}

			return 'Scale Imbalanced'; 
			console.log(pushData());
			document.scalebalancing.txtres.value=res;
}
		
	
	</script>

I admit I have not looked much, but this is eye catching: as the return statement returns something and stops the function, everything that is after a return statement inside a function is not executed

Can I also advice you tidy up your code? You can just paste your JavaScript in something like jsfiddle.net and press tidy and it will be easier to read

function pushData() {
  var w1, w2, res;
  var weights = [1, 2, 7, 7];
  w1 = Number(document.scalebalancing.txtnum1.value);
  w2 = Number(document.scalebalancing.txtnum2.value);

  for (var i = 0; i < weights.length; i++) {
    if (w1 + weights[i] === w2 || w2 + weights[i] === w1) {
      return '' + weights[i];
    }
    for (var j = i + 1; j < weights.length; j++) {
      if (w1 + weights[i] + weights[j] === w2 || w2 + weights[i] + weights[j] === w1 || w1 + weights[i] === w2 + weights[j] || w2 + weights[i] === w1 + weights[j]) {
        return '' + weights[i] + ',' + weights[j];

      }
    }
  }
  console.log(pushData());
  res=(pushData());
  document.scalebalancing.txtres.value = res;
  return 'Scale Imbalanced';

}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

thanks you very much. I will take note next time.