1

I am trying to loop through the value entered from 'Info1" and displaying range sliders.

Ex: Info1 is 10, then would like to add 10 range sliders. I get this error "Uncaught TypeError: info1 is not a function at HTMLInputElement.onkeyup"

Could anyone help me. Thanks in Advance.

<script type="text/javascript" charset="utf-8">
function info1()
{
  var num1 = document.getElementById("info1").value;  
  if (num1 == '')
      num1 = '0'; 
  alert(num1);
}
</script>
<html>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<?php $x=1; $num1 = 0;?>

<form method ="post" action ="info.php" >

 <table>
  <tr> <th> numeric A: </th> 
  <td> <input type="text" name="info1" id="info1" onkeyup="info1()" value=""> </td> 
  </tr>
  
 <?php 
while($x <= $num1) { ?>
 <tr> <th> sliders</th>
 <td><input type="Range" name="slider" min="0" max="1000" step="100" value="0"></input></td>
   <?php $x++; } ?>

<tr> <td> </td> 
 <td> <input type ="submit" name="insert" value ="Add"> 
 </td> 
</tr>
</table>
</form>

</body>
</html>
Varun
  • 21
  • 1
  • 8
  • 1
    Choose a function name that is different from the ID, or use standard [`addEventListener`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener). – Sebastian Simon Mar 25 '18 at 19:07
  • Possible duplicate of [Firing JS function from onkeyup event input](https://stackoverflow.com/questions/24588547/firing-js-function-from-onkeyup-event-input) – Sebastian Simon Mar 25 '18 at 19:13
  • Thanks for your reply. yes, I changed the function name to info_1... i get alert with the info1 value correctly. But range sliders are not getting added. It doesn't trigger. Is any way to trigger to add range sliders. – Varun Mar 25 '18 at 19:43
  • You need the `change` event for this. – Sebastian Simon Mar 25 '18 at 19:49

1 Answers1

1

Some browsers take the ids of elements and make them into global variables, so your function info1 is replaced by your info1 element. Change either the name of the function or the id of the element.

Musa
  • 96,336
  • 17
  • 118
  • 137