ASP inside a JavaScript Function

ASP inside a JavaScript Function

am 02.01.2007 19:16:39 von dwaldman

I am having trouble with a JavaScript Function that includes ASP in it.
The function almost works, I was wondering if someone can take a look
at it to see if the ASP in the function is the cause of the
malfunction.

There is a form where a user will input a number they are working on
and the onchange event of the field calls a function that will
auto-calculate what is already in the DB vs the number they are
updating it with.

For example: It there is 10 in the DB and the user wants to update
that with 5 more they will put in only the number 5 and the function
will add the recordset (10) to the number they input to give a result
of 15 in a hidden field. When the form is submitted the hidden field
updates the DB.

Here is the code:

<%While ((Repeat1__numRows <> 0) AND (NOT rsT.EOF)) %>
<% i=rsT.Fields.Item("idtrans").Value%>
function Add(<%=i%>)
{
var num1 = document.form2.bagqty<%=i%>.value;
var num2 = document.form2.hdntot<%=i%>.value ;
document.form2.hdnbagqty<%=i%>.value = parseFloat(num1) +
parseFloat(num2);
}
<%Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsT.MoveNext()
Wend%>

This works fine and gives something like this when the page is live:

function Add(16)

{

var num1 = document.form2.bagqty16.value;

var num2 = document.form2.hdntot16.value ;

document.form2.hdnbagqty16.value = parseFloat(num1) +

parseFloat(num2);

}



function Add(17)

{

var num1 = document.form2.bagqty17.value;

var num2 = document.form2.hdntot17.value ;

document.form2.hdnbagqty17.value = parseFloat(num1) +

parseFloat(num2);

}

But when a number is inputed in the bagqty field 2 errors are
happening:

Object expected

and

Expected identifier

I can explain more and give more code if need be. Does anyone see what
i may be doing wrong?

Respectfully,

Danny

Re: ASP inside a JavaScript Function

am 02.01.2007 19:28:47 von exjxw.hannivoort

Mangler wrote on 02 jan 2007 in microsoft.public.inetserver.asp.general:

> <%While ((Repeat1__numRows <> 0) AND (NOT rsT.EOF)) %>
[..]
> function Add(<%=i%>)
[...]

so you are making a series of clientsided functions all called

Add()

???

> function Add(16) {
> var num1 = document.form2.bagqty16.value;

> function Add(17)

This is nonsense,
you cannot define a function with a constant as parameter

And when you define the same function a second time, te first one gets
overwritten.



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Re: ASP inside a JavaScript Function

am 02.01.2007 19:33:09 von dwaldman

Evertjan. wrote:
> This is nonsense,
> you cannot define a function with a constant as parameter
>
> And when you define the same function a second time, te first one gets
> overwritten.
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Suggestions???

The reason it is set up like that is because there is a mulitple update
performed on the page.

Re: ASP inside a JavaScript Function

am 02.01.2007 19:37:09 von dwaldman

Evertjan. wrote:
> so you are making a series of clientsided functions all called
>
> Add()
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

One more thing to add, the functions are different.

function Add(<%=i%>)

With the loop gives a list a fuctions like

Add(3)
Add(4)
Add(6)
Etc....


Be easy on me here, I barely know what I am doing with functions.

Re: ASP inside a JavaScript Function

am 02.01.2007 20:05:05 von exjxw.hannivoort

Mangler wrote on 02 jan 2007 in microsoft.public.inetserver.asp.general:

>
> Evertjan. wrote:
>> so you are making a series of clientsided functions all called
>>
>> Add()
>>
>
> One more thing to add, the functions are different.
>
> function Add(<%=i%>)

Please first forget about the ASP part and try to build a clientside
javascript code that is legal and working.

> With the loop gives a list a fuctions like
>
> Add(3)
> Add(4)
> Add(6)
> Etc....

No these are not different functions,
they are seperate calls executing one and the same function.

> Be easy on me here, I barely know what I am doing with functions.

The statement word "function" starts the definition of a function.

function Add(7) {alert('hello');};

is illegal/not working, because in the parameter field, only variable
names are allowed, that can be filled with a litteral value or a variable
or a script that results in such value.

Example of a correct functions:



======================

Again: please be proficient with clientside javascript,
before you go using Serverside script [eiter ASP-vbs or ASP-js]
into the clientside script.



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Re: ASP inside a JavaScript Function

am 02.01.2007 20:13:11 von dwaldman

> Evertjan. wrote:
> Please first forget about the ASP part and try to build a clientside
> javascript code that is legal and working.

Will do.

> Again: please be proficient with clientside javascript,
> before you go using Serverside script [eiter ASP-vbs or ASP-js]
> into the clientside script.
>
Point taken, thanks for the help. Back to the drawing board!!