Variable in funcion

M

Mangler

I am having a heck of a time because I dont know jscript; hope someone
can help....

I have a function that adds to form fields,, easy right?

function Add()
{
var num1 = document.form2.bagqty.value;
var num2 = document.form2.hdntot.value;
document.form2.hdnbagqty.value = parseFloat(num1) +
parseFloat(num2);
}

The issue I have is that the form field hdnbagqty has an ASP variable
attached to it as a unique name so mutliple fields can be updated on
the same page. For example:

hdnbagqty<%=intRecID%> is the name so when the query is run it shows
.....

hdnbagqty1
hdnbagqty2
hdhbagqty3

so an array is created based on the unique number and the statement
knows which row to update and so on....

The purpose of that function is to auto calculate what gets updated. I
just cant figure out how to get that unique name into that function.
 
P

pangea33

Mangler said:
I am having a heck of a time because I dont know jscript; hope someone
can help....

I have a function that adds to form fields,, easy right?

function Add()
{
var num1 = document.form2.bagqty.value;
var num2 = document.form2.hdntot.value;
document.form2.hdnbagqty.value = parseFloat(num1) +
parseFloat(num2);
}

The issue I have is that the form field hdnbagqty has an ASP variable
attached to it as a unique name so mutliple fields can be updated on
the same page. For example:

hdnbagqty<%=intRecID%> is the name so when the query is run it shows
....

hdnbagqty1
hdnbagqty2
hdhbagqty3

so an array is created based on the unique number and the statement
knows which row to update and so on....

The purpose of that function is to auto calculate what gets updated. I
just cant figure out how to get that unique name into that function.

Try something like this:

function Add() {
var i = 0;
var num1 = 0;
var num2 = 0;
var nMaxCnt = 10;
for (i=1; i<=nMaxCnt; i++) {
num1 = eval("document.form2.bagqty"+i+".value");
num2 = eval("document.form2.hdntot"+i+".value");
eval("document.form2.hdnbagqty"+i+".value = parseFloat(num1) +
parseFloat(num2)");
}
}
 
L

Lee

pangea33 said:
Try something like this:

function Add() {
var i = 0;
var num1 = 0;
var num2 = 0;
var nMaxCnt = 10;
for (i=1; i<=nMaxCnt; i++) {
num1 = eval("document.form2.bagqty"+i+".value");
num2 = eval("document.form2.hdntot"+i+".value");
eval("document.form2.hdnbagqty"+i+".value = parseFloat(num1) +
parseFloat(num2)");
}
}

PLEASE DON'T try that. Please don't ever suggest that.
If you won't read the FAQ before asking questions,
please at least read it before posting answers.

http://www.jibbering.com/faq/#FAQ4_40

num1 = document.forms2.elements["bagqty"+i].value;


--
 
P

pangea33

Lee said:
pangea33 said:
Try something like this:

function Add() {
var i = 0;
var num1 = 0;
var num2 = 0;
var nMaxCnt = 10;
for (i=1; i<=nMaxCnt; i++) {
num1 = eval("document.form2.bagqty"+i+".value");
num2 = eval("document.form2.hdntot"+i+".value");
eval("document.form2.hdnbagqty"+i+".value = parseFloat(num1) +
parseFloat(num2)");
}
}

PLEASE DON'T try that. Please don't ever suggest that.
If you won't read the FAQ before asking questions,
please at least read it before posting answers.

http://www.jibbering.com/faq/#FAQ4_40

num1 = document.forms2.elements["bagqty"+i].value;


--

My apologies
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top