Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making Changes to a form field 3

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
Guys,

I have a JS function na done of the things it does is to add 1 to a hidden form field which is used as a counter. the code is simple:

document.ProdForm.numRows.value += 1

However, numRows is initialised at 2 and when the above line is carried out numRows contains 21. How can I get JS to add the values rather than concatenate them??
Mise Le Meas,

Mighty :)
 
I get this problem one time and I solve it with this sample of code :

var myCounter;
myCounter = parseFloat(document.forms[0].myHidden.value);
myCounter = myCounter + 1;
document.forms[0].myHidden.value = myCounter;

I don't know why it doesn't work with your sample but try mine perhaps it will solve your problem !!

Hope this helps
 
"I don't know why it doesn't work with your sample" --> because numRows.value is a STRING and adding a number to a string returns a string with the number appended to the end
so "2" + "1" = "21" is normal
 
And what about this iza :

I found a bug with the parseInt() method !!
try parseInt(08) !! it returns 0 !!
I don't know why but I get this problem when I was checking my Dates format !!
D'you know something about that ??
 
no it's not a bug
if you use parseint, precise the radix
parseint(08) assumes you're in octal radix because the value starts with a 0 (if i remember well ... if you want all the details, either go to any ref site (devedge or msdn) or perform a search on this forum with parseint as a keyword - i copied pasted once the devedge doc here
(i anwer this at least once a month !!!)

so the proper use of parseInt is parseInt(08, 10) as we're in decimal radix ;]

hope your date functions will soon be fixed !!
 
thxs iza !!
My date functions works properly, you can take a look of it in the FAQ Area ;-)
 
seen ! great :)
(just a note : i usually use an array for number of days in months, so i don't check if month==4 ..., myarray[month] equals the number of days (of course this requires to have a normal_array and a leap_year_array) - i don't know which solution is better tho)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top