pass value html to javascript code example

Example 1: How to Pass Parameter in JavaScript Function From Html

<!DOCTYPE html>
<html>
<head>
	<title>function parameters javascript</title>
</head>
<body>
<button onclick="myfunctionName('rohan')">Click</button>

<script type="text/javascript">
	
	function myfunctionName(a){

		alert(a);
		
	}

</script>
</body>
</html>

Example 2: passing html vlaues to Javascript function

<body>
<h1>Adding 'a' and 'b'</h1>

  a: <input type="number" name="a" id="a"><br>
  b: <input type="number" name="b" id="b"><br>
  <button onclick="add(document.getElementById('a').value,document.getElementById('b').value)">Add</button>

<script>
  function add(a,b) {
    var sum = parseInt(a) + parseInt(b);
    alert(sum);
  }
</script>
</body>