Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic 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 July 25th, 2003, 12:26 AM
Registered User
 
Join Date: Jul 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default asp include file?

include an asp file in another asp file.

i write a function with javascript in an asp file named 'com_setmenu.asp',and want to inculde it to anothen asp file named 'house.asp'.

com_setmenu.asp:
    <SCRIPT LANGUAGE="JavaScript">
      Â¡Â¡function setmenu1(){.....}
    </SCRIPT>

house.asp:

    ...
    <select name="select" size="1" LANGUAGE=javascript onchange="setmenu1()">
    ...

IE6 sent out an error:
    'lack of object'

i write this function in 'house.asp' directly,there is no error!!


 
Old July 25th, 2003, 04:36 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The problem (or feature) with ASP include files is that they are processed by the server. Their content is not send to the browser as is. So they won't work like regular JavaScript includes.

You have (at least) two options:

1. Move the client side JavaScript function to a client side .js file and use <script language="JavaScript" src="MyFunctions.js"></script> in your ASP file to have the browser request the .js file.

2. Use Response.Write to have the ASP include file output the function to the browser:
Code:
Response.Write("<SCR" & "IPT LANGUAGE=""JavaScript"">" & vbCrLf)
Response.Write(vbTab & "¡¡function setmenu1(){.....}" & vbCrLf)
Response.Write("</SC" & "RIPT>")
You'll need to split up the <script> tags, because otherwise the ASP processor thinks you are trying to close or open a server side script tag.

HtH

Imar



---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old July 25th, 2003, 07:11 AM
Registered User
 
Join Date: Jul 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks a lot~~~

 
Old July 25th, 2003, 06:50 PM
Authorized User
 
Join Date: Jun 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

1) it appears that IE cannot see the function setmenu1(), another word, cannot see the include file "com_setmenu.asp".

If you use #include file="com_setmenu.asp", make sure it resides in the same folder as "house.asp", otherwise, try:
#include virtual="/YourProject/com_setmenu.asp
assume "com_setmenu.asp" is under project folder.

2) you can use both server and client #include as following:



<%
'server code...
%>
<HTML>
<HEAD>


  <SCRIPT LANGUAGE="JavaScript" SRC="client_script2.js"></SCRIPT>
  <SCRIPT LANGUAGE="VBScript" SRC="client_script3.vbs"></SCRIPT>

  <SCRIPT LANGUAGE="JavaScript">
    //your main script goes here
  </SCRIPT>
</HEAD>
<BODY>
  <SELECT .....>
</BODY>
</HTML>

//with "client_script2.js" and "client_script3.vbs" without the <SCRIPT> tag

hope this help,
Khoa Nguyen





Similar Threads
Thread Thread Starter Forum Replies Last Post
difference between include file & include virtual crmpicco Classic ASP Basics 2 January 23rd, 2006 11:50 AM
Executing asp Include file withing HTML content itHighway HTML Code Clinic 4 August 7th, 2005 01:03 PM
include php inside the asp file karib Classic ASP Databases 2 November 25th, 2003 03:51 PM





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