# Problems with calling functions in html

Page 1 of 1

## 13 Replies - 656 Views - Last Post: 19 June 2013 - 01:08 PM

### #1 AllHighway

Reputation: 0
• Posts: 68
• Joined: 08-February 12

# Problems with calling functions in html

Posted 18 June 2013 - 08:55 PM

I am trying to create a calculator through javascript. I am having problems passing the numberArr to get the length of the array, that is created from user input. I am not sure what I am missing in the following code. Any help is greatly appreciated.

```<!DOCTYPE html>
<html>
<script language="javascript">
function calculate()
{
var nums=insertValue(number.value);
var numbers=calcNum(nums);
document.getElementById("numOfEle").value = numbers;
}
function insertValue(num)
{
var num =document.getElementById("number").value;
var inputArr=num.split(" ");
var numberArr=new Array();

for(var i=0;i<inputArr.length;i++)
{
numberArr[i]=parseInt(inputArr[i]);
display=numberArr;
document.getElementById("display").innerHTML="Elements Entered: " + numberArr;
};
return numberArr;
};
function calcNum(arr)//calculates the number of elements in an array
{
return arr.length;
};
</script>
<body>
<form>
<h1>Enter data</h1>
<h2>Separate each number with a space.</h2>
<input id="number" type="text" placeholder="Enter a number" />
<br>
<input id "numOfEle" type="text" name= "numElements">Number of the elements
<br>
</form>
<div id="display"></div>
</body>
</html>
```

This post has been edited by AllHighway: 18 June 2013 - 09:07 PM

Is This A Good Question/Topic? 0

## Replies To: Problems with calling functions in html

### #2 Dormilich

• 痛覚残留

Reputation: 3820
• Posts: 11,701
• Joined: 08-June 10

## Re: Problems with calling functions in html

Posted 18 June 2013 - 10:15 PM

line #37: ain’t there something missin’?

PS: check the Error Console

This post has been edited by Dormilich: 18 June 2013 - 10:16 PM

### #3 AllHighway

Reputation: 0
• Posts: 68
• Joined: 08-February 12

## Re: Problems with calling functions in html

Posted 19 June 2013 - 03:31 AM

Is it that the value cannot equal null? That is what the error checking said.

### #4 Dormilich

• 痛覚残留

Reputation: 3820
• Posts: 11,701
• Joined: 08-June 10

## Re: Problems with calling functions in html

Posted 19 June 2013 - 03:47 AM

you have a very simple typo that leads to the element-does-not-exist error.

### #5 AllHighway

Reputation: 0
• Posts: 68
• Joined: 08-February 12

## Re: Problems with calling functions in html

Posted 19 June 2013 - 04:22 AM

Dormilich, on 19 June 2013 - 03:47 AM, said:

you have a very simple typo that leads to the element-does-not-exist error.

<input id="numbers"

I see it. I'll try it when I get home. Thanks

• Cheese and Sprinkles

Reputation: 464
• Posts: 1,984
• Joined: 30-April 10

## Re: Problems with calling functions in html

Posted 19 June 2013 - 07:30 AM

What you need is an equal sign on line 37
```<input id="numOfEle"
```

### #7 AllHighway

Reputation: 0
• Posts: 68
• Joined: 08-February 12

## Re: Problems with calling functions in html

Posted 19 June 2013 - 07:47 AM

I got it. Thanks for the input.

### #8 AllHighway

Reputation: 0
• Posts: 68
• Joined: 08-February 12

## Re: Problems with calling functions in html

Posted 19 June 2013 - 11:05 AM

I made the correction, but the code is still not executing.

### #9 andrewsw

• Well, I'll need some beer.

Reputation: 4976
• Posts: 18,847
• Joined: 12-December 12

## Re: Problems with calling functions in html

Posted 19 June 2013 - 11:57 AM

AllHighway, on 19 June 2013 - 06:05 PM, said:

I made the correction, but the code is still not executing.

Your code works fine for me, after inserting the missing equals-sign. Perhaps you should re-post your current code.

### #10 AllHighway

Reputation: 0
• Posts: 68
• Joined: 08-February 12

## Re: Problems with calling functions in html

Posted 19 June 2013 - 12:02 PM

In the calcNum(arr). I am trying to get the length of the user input array to print in the text box numOfEle.

### #11 andrewsw

• Well, I'll need some beer.

Reputation: 4976
• Posts: 18,847
• Joined: 12-December 12

## Re: Problems with calling functions in html

Posted 19 June 2013 - 12:07 PM

AllHighway, on 19 June 2013 - 07:02 PM, said:

In the calcNum(arr). I am trying to get the length of the user input array to print in the text box numOfEle.

Yes, as I say, it works for me (in Google Chrome).

### #12 AllHighway

Reputation: 0
• Posts: 68
• Joined: 08-February 12

## Re: Problems with calling functions in html

Posted 19 June 2013 - 12:27 PM

I got it working now. LOL I was working on some older code and not the revised one. Thanks everyone for the help.

```<!DOCTYPE html>
<html>
<script language="javascript">
function calculate()
{
var nums=insertValue(number.value);
var numbers=calcNum(nums);
document.getElementById("numOfEle").value = numbers;
}
function insertValue()
{
var num =document.getElementById("number").value;
var inputArr=num.split(" ");
var numberArr=new Array();

for(var i=0;i<inputArr.length;i++)
{
numberArr[i]=parseInt(inputArr[i]);
//display=numberArr;

document.getElementById("display").innerHTML=" Elements Entered: " + numberArr;
};
return numberArr;
};
function calcNum(arr)//calculates the number of elements in an array
{

return arr.length;
};
</script>
<body>
<form>
<h1>Enter data</h1>
<h2>Separate each number with a space.</h2>
<input id="number" type="text"  placeholder="Enter a number" />
<br>
<input id="numOfEle" type="text" name= "numElements">Number of the elements
<br>
</form>
<div id="display"></div>
</body>
</html>

```

### #13 andrewsw

• Well, I'll need some beer.

Reputation: 4976
• Posts: 18,847
• Joined: 12-December 12

## Re: Problems with calling functions in html

Posted 19 June 2013 - 12:53 PM

AllHighway, on 19 June 2013 - 07:27 PM, said:

I got it working now. LOL I was working on some older code and not the revised one. Thanks everyone for the help.

Actually, this did occur to me, but I thought "no, surely not"

### #14 AllHighway

Reputation: 0
• Posts: 68
• Joined: 08-February 12

## Re: Problems with calling functions in html

Posted 19 June 2013 - 01:08 PM

Yep, the old code left the return out. smh!