femindharamshi10
Posts: 102
Joined: Thu Jan 07, 2016 1:28 pm

html javascript

Sun Feb 14, 2016 9:33 am

i tried putting this code on my pi but it doesnt work :

Code: Select all

<html>
<head>
</head>
<body>

<script>
function calc(id,id2)
{
  var name="t" + id;
  var name2="t" + id2;
  var b=document.getElementsByName(name).value;
  var c=document.getElementsByName(name2).value;
  b = b.replace(/[^0-9\.]+/g, "");
  c = c.replace(/[^0-9\.]+/g, "");
  var x = Number(b);
  var y = Number(c);
  var a = +x + y;
  document.getElementsByName("t3").value = a;
}
</script>
  <input type="text" name="t1">
  <input type="text" name="t2">
  <input type="text" name="t3" onclick="calc(1,2)">
</body>
</html>
can u tell me my mistake

elatllat
Posts: 1337
Joined: Sat Dec 17, 2011 5:05 pm

Re: html javascript

Sun Feb 14, 2016 10:43 am

document.getElementsByName(name)[0].value;


Use the web browser developer tools and it will tell you this sort of thing.
SBC with 32GB RAM: https://hardkernel.com

FAQ : https://raspberrypi.stackexchange.com

Unanswered: https://www.raspberrypi.org/forums/search.php?search_id=unanswered

femindharamshi10
Posts: 102
Joined: Thu Jan 07, 2016 1:28 pm

Re: html javascript

Mon Feb 15, 2016 10:52 am

elatllat wrote:document.getElementsByName(name)[0].value;


Use the web browser developer tools and it will tell you this sort of thing.
okay sure... anyways thank you

Return to “General discussion”