Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old January 2nd, 2007, 06:25 PM
Mangler
Guest
 
Posts: n/a
Default ASP inside a JavaScript Function

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

  #2  
Old January 2nd, 2007, 06:35 PM
Mangler
Guest
 
Posts: n/a
Default Re: ASP inside a JavaScript Function


Evertjan. wrote:
Quote:
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.

  #3  
Old January 2nd, 2007, 06:35 PM
Evertjan.
Guest
 
Posts: n/a
Default Re: ASP inside a JavaScript Function

Mangler wrote on 02 jan 2007 in microsoft.public.inetserver.asp.general:
Quote:
<%While ((Repeat1__numRows <0) AND (NOT rsT.EOF)) %>
[..]
Quote:
function Add(<%=i%>)
[...]

so you are making a series of clientsided functions all called

Add()

???
Quote:
function Add(16) {
var num1 = document.form2.bagqty16.value;
Quote:
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)
  #4  
Old January 2nd, 2007, 06:45 PM
Mangler
Guest
 
Posts: n/a
Default Re: ASP inside a JavaScript Function


Evertjan. wrote:
Quote:
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.

  #5  
Old January 2nd, 2007, 07:15 PM
Mangler
Guest
 
Posts: n/a
Default Re: ASP inside a JavaScript Function

Quote:
Evertjan. wrote:
Please first forget about the ASP part and try to build a clientside
javascript code that is legal and working.
Will do.
Quote:
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!!

  #6  
Old January 2nd, 2007, 07:15 PM
Evertjan.
Guest
 
Posts: n/a
Default Re: ASP inside a JavaScript Function

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



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

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles