Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 19th, 2004, 02:54 AM
Authorized User
 
Join Date: Jan 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default code runs when not suppose to! (solved)

hi, hope i post it in the correct forum
i am new to javascript so maybe i missed something obvious here, but any help is appreciated

i have a subprocedure coded in vbscript called deleteAll.
then i have a function for a button in javascript that needs to call deleteAll.
but my page will load with a blank page when i click on that button, and when i view source i realise there is suppose to be an error messagea lthough the page is blank

the error message i see in the source is this:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'deleteAll'

here is the javascript code:
<script language="JavaScript">
function checkAll() {
var agree = confirm("Are you sure you want to do this?");
if (agree)
<%=deleteAll%>;
}
</script>

anybody knows whats wrong???
 
Old February 19th, 2004, 03:07 AM
Authorized User
 
Join Date: Jan 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok. i realise its that '=' in the <%=deleteAll%>, just remove it and its fine, but i found another problem.

when my page loads, it runs the the code in the deleteAll subprocedure straightaway, although the only place i called deleteAll is in my javascript function, and the only place i called that function is in my button.

why is it so??


 
Old February 19th, 2004, 03:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

dhaywires,
When code is within the <%%> tags it is run on the server before the page is sent to the client.

So no code within <%%> can be run in the browser.
(There is an exception to this where you write a string containing javascript code to the browser, but I don't think this suits your intent).

I assume by the name "deleteAll" that the code is intended to delete record/s from a database.

If this is the case then you must make a return trip to the server, where the code is run to access the database.

This is an essential concept to grasp if you wish to write ASP, I would suggest doing some research on client side vs server side code to fully understand what you are asking the browser/server to do.

Here is one to start with
http://www.metalusions.com/backstage/articles/12/



======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old February 19th, 2004, 03:30 AM
Authorized User
 
Join Date: Jan 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for replying rodmcleay

i've done some research beforehand and i've read the article you posted, but one thing cofuses me
i got another page with a javascript function generated by dreamweaver plus one line of code i added in myself for a button, the function is this

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_goToURL() { //v3.0
<%session("cancelflag") = "on"%>; --->i added this myself
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>

like you said, codes within <%%> are run once on the server and thats it, but with the page that contains this function, the <%session("cancelflag") = "on"%>; doesnt run when the page is loaded until i actually click on the button, how different is that from my original problem regarding the procedure in the function and yet it's executed when the page loads

any ideas?? plz help

 
Old February 19th, 2004, 03:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

dhaywirex,
It is the same.

Im afraid the <% session("cancelflag") = "on"%> is run before the page [u]is</u> send to the browser.

But I would guess that you have now way of telling that until the button is pressed.

I will post an example to explain my point, just a minute.



======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old February 19th, 2004, 03:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Try my full page code example below
Code:
<% @language = "vbscript" %>
<html>
<head>
    <title>Untitled</title>
</head>
<body>
<%
    'I am setting the 
    session("testVal") = "THIS IS BEFORE THE PAGE IS SEND"
%>
<script language=javascript>
    //This JS Function Will Never be called in my page.
    //But the code between tags will run on server
    function NeverCalled()
    {<% session("testVal") = "THIS IS IN THE NeverCalled FUNCTION"%>}

    function testSession()
    {
        //You will see that the value of test val has changed to hte second string.
        alert('<%= session("testVal")%>');
    }
</script>
<input type="button" onclick="testSession()" value="Show the session value">
</body>
</html>
======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old February 19th, 2004, 03:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

In fact if you look at the html source code for the page where you had

function MM_goToURL() { //v3.0
<%session("cancelflag") = "on"%>; --->i added this myself
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


You will see that nothing is writen to where you put <%session("cancelflag") = "on"%>.
As nothing is writen to where i put {<% session("testVal") = "THIS IS IN THE NeverCalled FUNCTION"%>} in the html source



======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old February 19th, 2004, 03:55 AM
Authorized User
 
Join Date: Jan 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks rodmcleay
what a mistake i made, i didnt bother to verify if that script inside the function was run first

so back to my original question, does that mean that if i want to call the deleteAll procedure, i would have to do it with client-side script, for it to be called successfully in the function??

 
Old February 19th, 2004, 04:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Is the deleteAll going to access a database?



======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old February 19th, 2004, 04:06 AM
Authorized User
 
Join Date: Jan 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes, i intend to delete multiple records from a database, the recordset of which is already declared in the server-side script






Similar Threads
Thread Thread Starter Forum Replies Last Post
Not Suppose to offend aasiddle ASP.NET 2.0 Basics 4 March 16th, 2007 11:52 AM
NOT ISPOSTBACK code runs when Back Button clicked Ron Howerton VB.NET 2002/2003 Basics 1 September 28th, 2006 05:12 PM
Solved:VB Code Asks for Password to UnZip!! flashster BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 August 23rd, 2006 01:55 PM
Browser conflicts I suppose . . . Ross McVinnie Intro Programming 0 July 10th, 2006 05:32 PM
VB.NET Edition code problems Solved charul_shukla BOOK: ASP.NET Website Programming Problem-Design-Solution 5 July 11th, 2003 01:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.