ASP inside a JavaScript Function

M

Mangler

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
 
E

Evertjan.

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.
 
M

Mangler

Evertjan. said:
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.

Suggestions???

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

Mangler

Evertjan. said:
so you are making a series of clientsided functions all called

Add()

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.
 
E

Evertjan.

Mangler wrote on 02 jan 2007 in microsoft.public.inetserver.asp.general:
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:

<script type='text/javascript'>

function add7(x) {
return x + 7;
};

alert( add7(3) ); // this will alert with the value "10"

alert( add7('hi ') ); // this will alert with the valie "hi 7"

// ----------------------------

function add(x,y) {
return x + y;
};

alert( add(15,25) ); // this will alert with the value "40"


</script>

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

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

Mangler

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!!
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top