NaN error

S

sangram

i am calling these functions bellow while adding and deleting ,i am
getting NaN on html page.

i need early replay...
thanks
sangram

var dual=0;
function check1()
{
deleteRow(dual);
dual=0;
return true;
}

function check()
{

generateRow(dual);
dual=1;
return true;

}

function deleteRow(dual)
{
if(dual == 1)
{
var d1=document.getElementById("san1");
d1.innerHTML-="<lable>Company Name*</label>";
var d=document.getElementById("san");
d.innerHTML-="<input type='text' name='company' >";
}
return true;
}

function generateRow(dual)
{
if(dual < 1)
{
var d1=document.getElementById("san1");
d1.innerHTML+="<lable>Company Name*</label>";
var d=document.getElementById("san");
d.innerHTML+="<input type='text' name='company'>";
}
return true;


}



it returns NaN on the broweser..
i do not want to display that one...
 
W

web.dev

sangram said:
i am calling these functions bellow while adding and deleting ,i am
getting NaN on html page.
[snip]

it returns NaN on the broweser..
i do not want to display that one...

None of the functions you've shown are relevant to the error you're
seeing. NaN stands for "Not a Number". I'm assuming you're doing a
mathematical operation somewhere but I cannot tell with the code you've
presented. Try to give a minimal example of which the error still
reproduces.
 
F

Fred

sangram said:
i am calling these functions bellow while adding and deleting ,i am
getting NaN on html page.

i need early replay...

Then play it again... :)

[...]
function deleteRow(dual)
{
if(dual == 1)
{
var d1=document.getElementById("san1");
d1.innerHTML-="<lable>Company Name*</label>";
var d=document.getElementById("san");
d.innerHTML-="<input type='text' name='company' >";

While the + operator is overloaded to do both arithmetic addition and
string concatentation (and unary plus), the - operator is not similarly
overloaded: it works only as arithmetic subraction, not a kind of
replace operator. The variables being operated on must be numbers, not
strings.

You might also want to correct the "lable" tag name typo.

[...]
 
S

sangram

web.dev said:
sangram said:
i am calling these functions bellow while adding and deleting ,i am
getting NaN on html page.
[snip]

it returns NaN on the broweser..
i do not want to display that one...

None of the functions you've shown are relevant to the error you're
seeing. NaN stands for "Not a Number". I'm assuming you're doing a
mathematical operation somewhere but I cannot tell with the code you've
presented. Try to give a minimal example of which the error still
reproduces.

i am calling this add function on onclick event of one radio button and
deleting in another radio button..
 
S

sangram

Fred said:
sangram said:
i am calling these functions bellow while adding and deleting ,i am
getting NaN on html page.

i need early replay...

Then play it again... :)

[...]
function deleteRow(dual)
{
if(dual == 1)
{
var d1=document.getElementById("san1");
d1.innerHTML-="<lable>Company Name*</label>";
var d=document.getElementById("san");
d.innerHTML-="<input type='text' name='company' >";

While the + operator is overloaded to do both arithmetic addition and
string concatentation (and unary plus), the - operator is not similarly
overloaded: it works only as arithmetic subraction, not a kind of
replace operator. The variables being operated on must be numbers, not
strings.

You might also want to correct the "lable" tag name typo.

[...]

Thanks friend..
then how to do this..
how to delete the added text box.
 
F

Fred

sangram said:
Fred said:
sangram said:
i am calling these functions bellow while adding and deleting ,i am
getting NaN on html page.

i need early replay...

Then play it again... :)

[...]
function deleteRow(dual)
{
if(dual == 1)
{
var d1=document.getElementById("san1");
d1.innerHTML-="<lable>Company Name*</label>";
var d=document.getElementById("san");
d.innerHTML-="<input type='text' name='company' >";

While the + operator is overloaded to do both arithmetic addition and
string concatentation (and unary plus), the - operator is not similarly
overloaded: it works only as arithmetic subraction, not a kind of
replace operator. The variables being operated on must be numbers, not
strings.

You might also want to correct the "lable" tag name typo.

[...]
[...]
how to delete the added text box.

Use DOM methods. innerHTML is a kludge, but also very convenient. If
you want to remove all the content of the table cell, the simplest
method is to set its innerHTML to an empty string.

A more elegant method is to remove all its child nodes:

while (d1.firstChild) {
d1.removeChild(d1.firstChild);
}

If you want to remove particular nodes, you may need to use other
methods. It is impossible to recommend a suitable method without
understanding what you are trying to do or seeing the HTML you are
working on.
 
D

Dr J R Stockton

In comp.lang.javascript message
Thu said:
While the + operator is overloaded to do both arithmetic addition and
string concatentation (and unary plus), the - operator is not similarly
overloaded: it works only as arithmetic subraction,

There, "only" is not *quite* true. Unary minus changes sign, but does
not subtract.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top