473,398 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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

Jan 2 '07 #1
5 3113
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)
Jan 2 '07 #2

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.

Jan 2 '07 #3

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.

Jan 2 '07 #4
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:

<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)
Jan 2 '07 #5
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!!

Jan 2 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
2
by: Mountain Man | last post by:
Hi, I'm trying to use window.open from inside a user defined function, and it's not working. A code example is shown below. Thanks for any help you can give. Mountain Man ============ ...
7
by: sindre | last post by:
Hi, Some place I use links to submit forms instead of a submit button. The way I have done this is: <a href="javascript:document.getElementById('<?php print "delete$i"...
21
by: ryanmhuc | last post by:
I know the subject might be confusing. I am no beginner with javascript but I haven't been able to figure out how to get the javascript file name from code inside the file. So you have an HTML...
18
by: Chris Ianson | last post by:
Hi geniuses (or is that genii, or genies) The challenge is as above really. I have a page with an iframe in it, and need to call a JS function in the *parent* page, *from* inside the iframe. ...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
2
by: Daz | last post by:
Hi everyone. Sorry for the confusing subject, I couldn't think how best to word it. What I would like to know, is if there is an equivilant to this code, in using JSON. <script...
5
by: =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?= | last post by:
Hello, I've been trying to figure something out for the past few days and I can't seem to pinpoint what I'm doing wrong. I've been trying to call javascript from inside a <logic:equal>, but...
5
by: Lupus | last post by:
Hi everyone, I've got a problem with javascript. I have a webpage which contains some javascript functions and an iFrame which contains a second webpage: <html> <head> .... <script....>
3
by: SMH | last post by:
Normally an SVG document is loaded/parsed/interpreted inside an HTML document using an 'object' (or 'embed') element, although there are supposedly other ways too. The problem is, the SVG document...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.