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

June 20th, 2008, 11:58 PM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Insert ASP code in JS *need HELP*
Hello,
I have a problem. I have ASP code and Javascript code. Now, I want to access ASP code inside javascript code.
Here is the ASP code:
Hello,
I have a problem. I have ASP code and Javascript code. Now, I want to access ASP code inside javascript code.
Here is the ASP code:
<%
CONST C_prefix = "contains(.,'"
CONST C_midfix = "') or contains(.,'"
CONST C_suffix = "')"
Function CreateContainsList( fromStr )
Dim temp, re
' the regexp ensures that multiple spaces become single spaces
Set re = New RegExp
re.Pattern = "\s+"
re.Global = True
' so get an array of words via split...
temp = Split( re.Replace( Trim(fromStr), " " ), " " )
' and make it into the contains list via join and helpers
CreateContainsList = C_prefix & Join( temp, C_midfix ) & C_suffix
End Function
demo = request.Form("txtSearch")
path = "form/document[" & CreateContainsList(demo) & " ]//*"
'Response.Write ("<pre>" & demo & "" & path & "</pre>")
%>
And I want to print variable "path" inside javascript.
I tried like this but the "path" does not print out.
<script type="tex/javascript">
document.write("<%=path%>");
</script>
It showed an error. The error is : the "path" is undefined
|
|

June 21st, 2008, 01:01 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Well, if I had to guess, I'd say probably you put the JS code *before* the ASP code.
But that JS code is pretty worthless, anyway.
All it is going to produce in your HTML is
form/document[Contains(.,'something')]//*
It won't be legitimate JavaScript code.
It won't be legitimate HTML code.
It will just be a *STRING* that displays in the browser.
I hope you won't take this too unkindly, but you seem to be trying to run before you have learned to crawl.
You really need to go learn that basics of what you are trying to do.
WHY do you want to get this XPath expression??? WHERE do you want to USE it?
And in any case, since the code you show here is (sorry, but true) nonsense, maybe you need to show more code. In particular, show the code that will try to use the XPath.
|
|

June 21st, 2008, 01:10 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Looking at your posts over the last week, and in particular the posts here:
http://p2p.wrox.com/topic.asp?TOPIC_ID=72142
I think what you *POSSIBLY* need is much simpler than what you are trying to do here.
In the TOPIC 72142, you said that *THIS* code worked:
When I tried :
path="form/document[contains(.,'<%= request.Form("txtSearch")%>')]//*";
It works well.
So why are you now trying to CHANGE EVERYTHING???? Why not stick with that *kind* of format?
That is:
Code:
<%
' you can put all this code ANY PLACE on the page!!
' at the top, at the bottom, won't matter
CONST C_prefix = "contains(.,'"
CONST C_midfix = "') or contains(.,'"
CONST C_suffix = "')"
Function CreateContainsList( fromStr )
Dim temp, re
' the regexp ensures that multiple spaces become single spaces
Set re = New RegExp
re.Pattern = "\s+"
re.Global = True
' so get an array of words via split...
temp = Split( re.Replace( Trim(fromStr), " " ), " " )
' and make it into the contains list via join and helpers
CreateContainsList = C_prefix & Join( temp, C_midfix ) & C_suffix
End Function
' end of the function
%>
And now you will just replace *THIS* code:
path="form/document[contains(.,'<%= request.Form("txtSearch")%>')]//*";
with THIS code:
path="form/document[<%= CreateContainsList(request.Form("txtSearch"))%>)]//*";
It looks to me like that's all that is required. But of course I can't tell for sure.
|
|

June 21st, 2008, 02:03 AM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
When I use the code only like this:
path="form/document[contains(.,'<%=request.Form("txtSearch")%>')]//*";
I just can search with 1 word or the exact word.
Actually, the ASP run very well. But, I can not implemented inside javascript
|
|

June 21st, 2008, 11:59 AM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Can I change this ASP code into Javascript code? Because I can not access the variable "path" in Javascript.
Here is the ASP code:
<%
CONST C_prefix = "contains(.,'"
CONST C_midfix = "') or contains(.,'"
CONST C_suffix = "')"
Function CreateContainsList( fromStr )
Dim temp, re
' the regexp ensures that multiple spaces become single spaces
Set re = New RegExp
re.Pattern = "\s+"
re.Global = True
' so get an array of words via split...
temp = Split( re.Replace( Trim(fromStr), " " ), " " )
' and make it into the contains list via join and helpers
CreateContainsList = C_prefix & Join( temp, C_midfix ) & C_suffix
End Function
demo = request.Form("txtSearch")
path = "form/document[" & CreateContainsList(demo) & " ]//*"
Response.Write ("<pre>" & demo & "" & path & "</pre>")
%>
|
|

June 21st, 2008, 03:17 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
I give up. If you won't read what I write, then I can't help you.
I *clearly* showed you in my post just before this one the code that I think would work. I even put the appropriate JavaScript code in red for you.
Yet you persist on going back to my *DEMO* code, which was NEVER intended to be used as the "real thing". It's only purpose was to demo that my CreateContainsList function did what it was supposed to do.
|
|

June 22nd, 2008, 01:58 AM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm so sorry. I was just panic because of the error so I did not read your message carefully. Now, the program work very well. Yesterday, I got the error because I did not change like you said in red colour.
Thank you very much..You're the best
:)
Now, I want to make the same thing like that.
If I run the code that you gave to me, it would show the result like this:
form/document[contains(.,'doc') or contains(.,'pdf') or contains(.,'txt')]//*
How to change the "." become the type that I chose?
I mean like this:
I want to make like a simple advanced search. So, firstly, the user have to choose the category before he/she type the keyword.
So, it looks like this:
path="form/document[contains(<%=request.Form("search_by")%>,'<%= request.Form("txtSearch")%>')]//*";
if I choose "search_by" : author
and the keyword: ABC DEF
then it will show the path like this:
path="form/document[contains(author,'ABC') or contains(author,'DEF')]//*";
I hope you want to help me again
Thank you
|
|

June 22nd, 2008, 03:25 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Easy...SEVERAL CHANGES TO CODE. Best to copy/paste *ALL* of it.
Code:
<%
' you can put all this code ANY PLACE on the page!!
' at the top, at the bottom, won't matter
CONST C_prefix = "contains($$$,'"
CONST C_midfix = "') or contains($$$,'"
CONST C_suffix = "')"
Function CreateContainsList( fieldName, fromList )
Dim temp, re
' first, check the fieldname:
fieldName = Trim("" & fieldName)
' if not given, use period to mean all fields:
If fieldName = "" Then fieldName = "."
' the regexp ensures that multiple spaces become single spaces
Set re = New RegExp
re.Pattern = "\s+"
re.Global = True
' so get an array of words via split...
temp = Split( re.Replace( Trim(fromList), " " ), " " )
' and make it into the contains list via join and helpers
temp = C_prefix & Join( temp, C_midfix ) & C_suffix
' then, finally, replace all our $$$ markers with the field name:
CreateContainsList = Replace( temp, "$$$", fieldName )
End Function
' end of the function
%>
path="form/document[<%= CreateContainsList(request("search_by"), request("txtSearch"))%>)]//*";
***********
Note that if you don't give a field name for the first argument (if you pass blank or null), the code automatically uses "." instead.
|
|

June 22nd, 2008, 09:07 PM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have copied all the code and there is an error like this:
Microsoft VBScript runtime (0x800A01C2)
Wrong number of arguments or invalid property assignment: 'CreateContainsList'
|
|

June 23rd, 2008, 12:29 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Show the code you copied.
Don't type it in here. Actually copy/paste it from the code where you are getting the error.
I'm betting that you goofed on your copying of my code, but maybe not. So show your *existing* code, to be sure.
|
|
 |