PDA

View Full Version : How can I use ASP and Javascript together?


lovebearhk
08-20-2008, 12:10 PM
If (counter = 0) Then
Response.Write("zero")
Else
<script type="text/javascript" language="javascript" SRC="http://abc.asp">
</script>
<script type="text/javascript" language="javascript">
....
....
</script>


How can I use ASP and Javascript together? Thanks!

brazenskies
08-20-2008, 12:22 PM
what exactly do you want to achieve? Give us a better idea of that and we'll be able to make some suggestions

lovebearhk
08-20-2008, 08:14 PM
I would like to write an asp script that if (k >0), then read the xml file and output the message inside, else, read the js file and output the message inside.

I have successfully written the xml part and js part but dont know how to link up them.


<%
If ( k >0 ) Then
Set xmldoc = Server.CreateObject("Microsoft.XMLDOM")
xmldoc.load("http://abcd.xml")
For i=0 To (xmldoc.documentElement.ChildNodes.Length-1)
Response.Write "<br>" & xmldoc.documentElement.ChildNodes(i)
next

Else

<SCRIPT type="text/javascript" language="javascript" SRC="http://abcd.js"></SCRIPT>
<SCRIPT type="text/javascript" language="javascript">
var i = 1;
if (counter.length > 1){
while (i < counter.length) {
var msg= counter[i++];
document.write(msg);
}
}
</SCRIPT>
End IF
%>

brazenskies
08-20-2008, 08:36 PM
have you tried that to see what happens?

You'll need to stick and 'end if' at the end of it anyway!

lovebearhk
08-21-2008, 10:38 AM
It works now!! The problem is the pair of "<%, %>". Thanks anyway.:)

<%
If ( k >0 ) Then
Set xmldoc = Server.CreateObject("Microsoft.XMLDOM")
xmldoc.load("http://abcd.xml")
For i=0 To (xmldoc.documentElement.ChildNodes.Length-1)
Response.Write "<br>" & xmldoc.documentElement.ChildNodes(i)
next

Else
%>
<SCRIPT type="text/javascript" language="javascript" SRC="http://abcd.js"></SCRIPT>
<SCRIPT type="text/javascript" language="javascript">
var i = 1;
if (counter.length > 1){
while (i < counter.length) {
var msg= counter[i++];
document.write(msg);
}
}
</SCRIPT>
<%
End IF
%>