Quick question. I have some java script that looks like this;
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=imgObj.parentNode.parentNode.childNo des(6).innerText-imgObj.parentNode.parentNode.childNodes(9).childNo des(0).value
This takes a cell in a datagrid (innertext) and subtracts the value of a
text box (value) in another cell, then populates a second text box in a third
cell with the value. it works except for the value it is populating in the
third cell is "NaN", which I think is "Not a Numeric". I tried using the
val() clause to make the values numbers, but this did not work. How do I make
the text values numbers in javascript?
Thanks! 9 2595
suggestion:
Why not work it out through the Code Behind, and populate a hidden on the
page that the JavaScript can pick up
"Lyners" <Ly****@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com... Quick question. I have some java script that looks like this;
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=imgObj.parentNode.parentNode.childNo des(6).innerText-imgObj.parentNode.parentNode.childNodes(9).childNo des(0).value
This takes a cell in a datagrid (innertext) and subtracts the value of a text box (value) in another cell, then populates a second text box in a third cell with the value. it works except for the value it is populating in the third cell is "NaN", which I think is "Not a Numeric". I tried using the val() clause to make the values numbers, but this did not work. How do I make the text values numbers in javascript?
Thanks!
Hi Lyners,
use the parseInt or parseFloat:
parseInt("abc") // Returns NaN.
parseInt("12abc") // Returns 12.
parseFloat("abc") // Returns NaN.
parseFloat("1.2abc") // Returns 1.2.
HTH,
Phillip Williams http://www.societopia.net http://www.webswapp.com
"Lyners" wrote: Quick question. I have some java script that looks like this;
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=imgObj.parentNode.parentNode.childNo des(6).innerText-imgObj.parentNode.parentNode.childNodes(9).childNo des(0).value
This takes a cell in a datagrid (innertext) and subtracts the value of a text box (value) in another cell, then populates a second text box in a third cell with the value. it works except for the value it is populating in the third cell is "NaN", which I think is "Not a Numeric". I tried using the val() clause to make the values numbers, but this did not work. How do I make the text values numbers in javascript?
Thanks!
Hi Phillip,
I tried the parseFloat, but got the same results. Here's my javascript :
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=parseFloat(imgObj.parentNode.parentN ode.childNodes(6).innerText)-parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(0).value)
I'll try the parseInt.
Any suggestions?
Thanks
"Phillip Williams" wrote: Hi Lyners,
use the parseInt or parseFloat:
parseInt("abc") // Returns NaN. parseInt("12abc") // Returns 12. parseFloat("abc") // Returns NaN. parseFloat("1.2abc") // Returns 1.2.
HTH, Phillip Williams http://www.societopia.net http://www.webswapp.com
"Lyners" wrote:
Quick question. I have some java script that looks like this;
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=imgObj.parentNode.parentNode.childNo des(6).innerText-imgObj.parentNode.parentNode.childNodes(9).childNo des(0).value
This takes a cell in a datagrid (innertext) and subtracts the value of a text box (value) in another cell, then populates a second text box in a third cell with the value. it works except for the value it is populating in the third cell is "NaN", which I think is "Not a Numeric". I tried using the val() clause to make the values numbers, but this did not work. How do I make the text values numbers in javascript?
Thanks!
Hi Grant, when you say Code Behind, do you mean do the calculations on the
Post Back? I am trying to avaid doing a Post Back, What I want to do is have
the totals update on the fly while the user is editing the datagrid. There
are about 100 entries on the screen. If I did a Post back on everyone of
them, it would consume a lot of time.
Thanks!
"Grant Merwitz" wrote: suggestion:
Why not work it out through the Code Behind, and populate a hidden on the page that the JavaScript can pick up
"Lyners" <Ly****@discussions.microsoft.com> wrote in message news:EE**********************************@microsof t.com... Quick question. I have some java script that looks like this;
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=imgObj.parentNode.parentNode.childNo des(6).innerText-imgObj.parentNode.parentNode.childNodes(9).childNo des(0).value
This takes a cell in a datagrid (innertext) and subtracts the value of a text box (value) in another cell, then populates a second text box in a third cell with the value. it works except for the value it is populating in the third cell is "NaN", which I think is "Not a Numeric". I tried using the val() clause to make the values numbers, but this did not work. How do I make the text values numbers in javascript?
Thanks!
Hi Lyners,
You might want to do a diagnostic alert on each statement to find out if you
are picking the right node or not, e.g.
alert (imgObj.parentNode.parentNode.childNodes(6).innerT ext + "= " +
parseFloat(imgObj.parentNode.parentNode.childNodes (6).innerText));
alert(parseFloat(imgObj.parentNode.parentNode.chil dNodes(9).childNodes(0).value+
"=" +
parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(0).value));
Phillip Williams http://www.societopia.net http://www.webswapp.com
"Lyners" wrote: Hi Phillip, I tried the parseFloat, but got the same results. Here's my javascript:
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=parseFloat(imgObj.parentNode.parentN ode.childNodes(6).innerText)-parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(0).value) I'll try the parseInt.
Any suggestions?
Thanks
"Phillip Williams" wrote:
Hi Lyners,
use the parseInt or parseFloat:
parseInt("abc") // Returns NaN. parseInt("12abc") // Returns 12. parseFloat("abc") // Returns NaN. parseFloat("1.2abc") // Returns 1.2.
HTH, Phillip Williams http://www.societopia.net http://www.webswapp.com
"Lyners" wrote:
Quick question. I have some java script that looks like this;
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=imgObj.parentNode.parentNode.childNo des(6).innerText-imgObj.parentNode.parentNode.childNodes(9).childNo des(0).value
This takes a cell in a datagrid (innertext) and subtracts the value of a text box (value) in another cell, then populates a second text box in a third cell with the value. it works except for the value it is populating in the third cell is "NaN", which I think is "Not a Numeric". I tried using the val() clause to make the values numbers, but this did not work. How do I make the text values numbers in javascript?
Thanks!
Hi Phillip,
I should have remembered from your previous post to use the all important
alert when troubleshooting. What I have determined is that the parser doesn't
like the $ sign in the innertext field. If I have a number like 222.00 it
works, If I have $222.00 it doesn't work. I did find out I was referenceing
the wrong control, but I still have the NaN problems because of the "$"
problem.
Here is my updated code;
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=parseFloat(imgObj.parentNode.parentN ode.childNodes(6).innerText)-parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(1).value);
alert(imgObj.parentNode.parentNode.childNodes(6).i nnerText + "= " +
parseFloat(imgObj.parentNode.parentNode.childNodes (6).innerText));
alert(imgObj.parentNode.parentNode.childNodes(9).c hildNodes(1).value+ "=" +
parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(1).value));
Any suggestions?
Thank you!
"Phillip Williams" wrote: Hi Lyners,
You might want to do a diagnostic alert on each statement to find out if you are picking the right node or not, e.g. alert (imgObj.parentNode.parentNode.childNodes(6).innerT ext + "= " + parseFloat(imgObj.parentNode.parentNode.childNodes (6).innerText));
alert(parseFloat(imgObj.parentNode.parentNode.chil dNodes(9).childNodes(0).value+ "=" + parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(0).value));
Phillip Williams http://www.societopia.net http://www.webswapp.com
"Lyners" wrote:
Hi Phillip, I tried the parseFloat, but got the same results. Here's my javascript:
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=parseFloat(imgObj.parentNode.parentN ode.childNodes(6).innerText)-parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(0).value) I'll try the parseInt.
Any suggestions?
Thanks
"Phillip Williams" wrote:
Hi Lyners,
use the parseInt or parseFloat:
parseInt("abc") // Returns NaN. parseInt("12abc") // Returns 12. parseFloat("abc") // Returns NaN. parseFloat("1.2abc") // Returns 1.2.
HTH, Phillip Williams http://www.societopia.net http://www.webswapp.com
"Lyners" wrote:
> Quick question. I have some java script that looks like this; > > imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=imgObj.parentNode.parentNode.childNo des(6).innerText-imgObj.parentNode.parentNode.childNodes(9).childNo des(0).value > > This takes a cell in a datagrid (innertext) and subtracts the value of a > text box (value) in another cell, then populates a second text box in a third > cell with the value. it works except for the value it is populating in the > third cell is "NaN", which I think is "Not a Numeric". I tried using the > val() clause to make the values numbers, but this did not work. How do I make > the text values numbers in javascript? > > Thanks! >
I should add.... I guess what I am trying to do is add a field formated as
currency with another field. I wonder if I should have a hidden field with
the value minus the formating to add the columns together?
"Lyners" wrote: Hi Phillip, I should have remembered from your previous post to use the all important alert when troubleshooting. What I have determined is that the parser doesn't like the $ sign in the innertext field. If I have a number like 222.00 it works, If I have $222.00 it doesn't work. I did find out I was referenceing the wrong control, but I still have the NaN problems because of the "$" problem.
Here is my updated code;
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=parseFloat(imgObj.parentNode.parentN ode.childNodes(6).innerText)-parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(1).value);
alert(imgObj.parentNode.parentNode.childNodes(6).i nnerText + "= " + parseFloat(imgObj.parentNode.parentNode.childNodes (6).innerText));
alert(imgObj.parentNode.parentNode.childNodes(9).c hildNodes(1).value+ "=" + parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(1).value));
Any suggestions?
Thank you!
"Phillip Williams" wrote:
Hi Lyners,
You might want to do a diagnostic alert on each statement to find out if you are picking the right node or not, e.g. alert (imgObj.parentNode.parentNode.childNodes(6).innerT ext + "= " + parseFloat(imgObj.parentNode.parentNode.childNodes (6).innerText));
alert(parseFloat(imgObj.parentNode.parentNode.chil dNodes(9).childNodes(0).value+ "=" + parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(0).value));
Phillip Williams http://www.societopia.net http://www.webswapp.com
"Lyners" wrote:
Hi Phillip, I tried the parseFloat, but got the same results. Here's my javascript:
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=parseFloat(imgObj.parentNode.parentN ode.childNodes(6).innerText)-parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(0).value) I'll try the parseInt.
Any suggestions?
Thanks
"Phillip Williams" wrote:
> Hi Lyners, > > use the parseInt or parseFloat: > > parseInt("abc") // Returns NaN. > parseInt("12abc") // Returns 12. > parseFloat("abc") // Returns NaN. > parseFloat("1.2abc") // Returns 1.2. > > HTH, > Phillip Williams > http://www.societopia.net > http://www.webswapp.com > > > "Lyners" wrote: > > > Quick question. I have some java script that looks like this; > > > > imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=imgObj.parentNode.parentNode.childNo des(6).innerText-imgObj.parentNode.parentNode.childNodes(9).childNo des(0).value > > > > This takes a cell in a datagrid (innertext) and subtracts the value of a > > text box (value) in another cell, then populates a second text box in a third > > cell with the value. it works except for the value it is populating in the > > third cell is "NaN", which I think is "Not a Numeric". I tried using the > > val() clause to make the values numbers, but this did not work. How do I make > > the text values numbers in javascript? > > > > Thanks! > >
Hi Lyners,
To remove unwanted formatting characters from a string, I would use regular
expressions with the replace function, e.g. if you have $1,234,567 and wants
to get 1234567:
var textVal = " $ 1,234,567";
var numericVal=0;
var re=/\$+/g; //this is a regular expression to remove the $ sign
textVal = textVal.replace(re, ""); //this executes the regular expression
alert(textVal);
re=/(,)+/g; //this regular expression removes the commas
textVal = textVal.replace(re, "");
alert(textVal);
HTH,
Phillip Williams http://www.societopia.net http://www.webswapp.com
"Lyners" wrote: Hi Phillip, I should have remembered from your previous post to use the all important alert when troubleshooting. What I have determined is that the parser doesn't like the $ sign in the innertext field. If I have a number like 222.00 it works, If I have $222.00 it doesn't work. I did find out I was referenceing the wrong control, but I still have the NaN problems because of the "$" problem.
Here is my updated code;
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=parseFloat(imgObj.parentNode.parentN ode.childNodes(6).innerText)-parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(1).value);
alert(imgObj.parentNode.parentNode.childNodes(6).i nnerText + "= " + parseFloat(imgObj.parentNode.parentNode.childNodes (6).innerText));
alert(imgObj.parentNode.parentNode.childNodes(9).c hildNodes(1).value+ "=" + parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(1).value));
Any suggestions?
Thank you!
"Phillip Williams" wrote:
Hi Lyners,
You might want to do a diagnostic alert on each statement to find out if you are picking the right node or not, e.g. alert (imgObj.parentNode.parentNode.childNodes(6).innerT ext + "= " + parseFloat(imgObj.parentNode.parentNode.childNodes (6).innerText));
alert(parseFloat(imgObj.parentNode.parentNode.chil dNodes(9).childNodes(0).value+ "=" + parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(0).value));
Phillip Williams http://www.societopia.net http://www.webswapp.com
"Lyners" wrote:
Hi Phillip, I tried the parseFloat, but got the same results. Here's my javascript:
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=parseFloat(imgObj.parentNode.parentN ode.childNodes(6).innerText)-parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(0).value) I'll try the parseInt.
Any suggestions?
Thanks
"Phillip Williams" wrote:
> Hi Lyners, > > use the parseInt or parseFloat: > > parseInt("abc") // Returns NaN. > parseInt("12abc") // Returns 12. > parseFloat("abc") // Returns NaN. > parseFloat("1.2abc") // Returns 1.2. > > HTH, > Phillip Williams > http://www.societopia.net > http://www.webswapp.com > > > "Lyners" wrote: > > > Quick question. I have some java script that looks like this; > > > > imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=imgObj.parentNode.parentNode.childNo des(6).innerText-imgObj.parentNode.parentNode.childNodes(9).childNo des(0).value > > > > This takes a cell in a datagrid (innertext) and subtracts the value of a > > text box (value) in another cell, then populates a second text box in a third > > cell with the value. it works except for the value it is populating in the > > third cell is "NaN", which I think is "Not a Numeric". I tried using the > > val() clause to make the values numbers, but this did not work. How do I make > > the text values numbers in javascript? > > > > Thanks! > >
Phillip, Thanks again, you've done it.
Here is my final code;
var textval = imgObj.parentNode.parentNode.childNodes(6).innerTe xt;
var re=/\$+/g;
textval = textval.replace(re,"");
re =/(,)+/g;
textval = textval.replace(re,"");
var textval2 =
imgObj.parentNode.parentNode.childNodes(9).childNo des(1).value;
var re=/\$+/g;
textval2 = textval2.replace(re,"");
re =/(,)+/g;
textval2 = textval2.replace(re,"")
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=parseFloat(textval)-parseFloat(textval2);
Thanks again....
Lyners
"Phillip Williams" wrote: Hi Lyners,
To remove unwanted formatting characters from a string, I would use regular expressions with the replace function, e.g. if you have $1,234,567 and wants to get 1234567:
var textVal = " $ 1,234,567"; var numericVal=0; var re=/\$+/g; //this is a regular expression to remove the $ sign textVal = textVal.replace(re, ""); //this executes the regular expression alert(textVal);
re=/(,)+/g; //this regular expression removes the commas textVal = textVal.replace(re, ""); alert(textVal);
HTH, Phillip Williams http://www.societopia.net http://www.webswapp.com "Lyners" wrote:
Hi Phillip, I should have remembered from your previous post to use the all important alert when troubleshooting. What I have determined is that the parser doesn't like the $ sign in the innertext field. If I have a number like 222.00 it works, If I have $222.00 it doesn't work. I did find out I was referenceing the wrong control, but I still have the NaN problems because of the "$" problem.
Here is my updated code;
imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=parseFloat(imgObj.parentNode.parentN ode.childNodes(6).innerText)-parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(1).value);
alert(imgObj.parentNode.parentNode.childNodes(6).i nnerText + "= " + parseFloat(imgObj.parentNode.parentNode.childNodes (6).innerText));
alert(imgObj.parentNode.parentNode.childNodes(9).c hildNodes(1).value+ "=" + parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(1).value));
Any suggestions?
Thank you!
"Phillip Williams" wrote:
Hi Lyners,
You might want to do a diagnostic alert on each statement to find out if you are picking the right node or not, e.g. alert (imgObj.parentNode.parentNode.childNodes(6).innerT ext + "= " + parseFloat(imgObj.parentNode.parentNode.childNodes (6).innerText));
alert(parseFloat(imgObj.parentNode.parentNode.chil dNodes(9).childNodes(0).value+ "=" + parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(0).value));
Phillip Williams http://www.societopia.net http://www.webswapp.com
"Lyners" wrote:
> Hi Phillip, > I tried the parseFloat, but got the same results. Here's my javascript: > > imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=parseFloat(imgObj.parentNode.parentN ode.childNodes(6).innerText)-parseFloat(imgObj.parentNode.parentNode.childNodes (9).childNodes(0).value) > I'll try the parseInt. > > Any suggestions? > > Thanks > > "Phillip Williams" wrote: > > > Hi Lyners, > > > > use the parseInt or parseFloat: > > > > parseInt("abc") // Returns NaN. > > parseInt("12abc") // Returns 12. > > parseFloat("abc") // Returns NaN. > > parseFloat("1.2abc") // Returns 1.2. > > > > HTH, > > Phillip Williams > > http://www.societopia.net > > http://www.webswapp.com > > > > > > "Lyners" wrote: > > > > > Quick question. I have some java script that looks like this; > > > > > > imgObj.parentNode.parentNode.childNodes(10).childN odes(0).value=imgObj.parentNode.parentNode.childNo des(6).innerText-imgObj.parentNode.parentNode.childNodes(9).childNo des(0).value > > > > > > This takes a cell in a datagrid (innertext) and subtracts the value of a > > > text box (value) in another cell, then populates a second text box in a third > > > cell with the value. it works except for the value it is populating in the > > > third cell is "NaN", which I think is "Not a Numeric". I tried using the > > > val() clause to make the values numbers, but this did not work. How do I make > > > the text values numbers in javascript? > > > > > > Thanks! > > > This discussion thread is closed Replies have been disabled for this discussion. Similar topics
1 post
views
Thread by Building Blocks |
last post: by
|
53 posts
views
Thread by Cardman |
last post: by
|
7 posts
views
Thread by rick |
last post: by
|
1 post
views
Thread by bin_P19 P |
last post: by
|
7 posts
views
Thread by Jurek |
last post: by
|
4 posts
views
Thread by Rich_C |
last post: by
| | | | | | | | | | | | | | |