How to call Javascript from the server using Response.Write"window.document.writeln

Hi,

I have ASP application.  
I need to call Javascript from the server using Response.Write "window.document.writeln('<script language='Javascript'>')".
 I tried this:  Response.Write"window.document.writeln('<script" + " language" + "='javascript'" + ">)" but still doesn't work.
Can I call it some how?
AzBukaAsked:
Who is Participating?
 
COBOLdinosaurCommented:
You cannot call a javascript function on the client from the server.

As for the sending over data without th erefresh, the method using the hidden image in the IBM link look like the easiest approach.  However be aware that code using an image like that will be block by some firewalls, and it may be identified as a virus.  The other method using the iframe may trigger a security alert when yu submit depending on user settings.

As for the other one.  It needs code on the server to run, and I don't use ASP of VBscript, so I don't know what that has to look like.

However if the only way to do what you want requires calling a client side function from the server, it is not going to happen.  You have to have a client side event to fire a client side function.

Cd&
0
 
Ryan ChongCommented:
try:

Response.Write "<script language='Javascript'> window.document.writeln('hello world..') </script>"
0
 
Ryan ChongCommented:
or if it's only to display the value, you can always try like:

Response.Write "hello world.."
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
COBOLdinosaurCommented:
Response.Write"window.document.writeln('<sc'+'ript'" + " language" + "='javascript'" + ">)"

And do the closing tag as: '</scr+ipt>'

If javascript sees the script tag is stops executing the rest of the script.

Cd&

0
 
AzBukaAuthor Commented:
Hi COBOLdinosaur,

I tried this one but still doesn't work.
It returns:
at the begining: window.document.writeln(')
 then several window.document.writeln( with my result value)
end finaly at the end: window.document.writeln(");

The javascript client side has 2 text boxes (user and password) 3 dropdown menus and submit button. On click first I am validating client input if not empty I am sending to the server. In the server I am using VBScript. I am connectiong to the database check if user and password are OK then write to the DB their input. Next based on selected combination of dropdown menues I am opening appropriate recordset and input results into table. I am creating this table on the server using Response.Write "newWindow.document.writeln('<table Width=100% VALIGN=CENTER ALIGN=CENTER>');" etc.
I can see the result but it is not in a table form. This is because when result is back to the client I will need to call Javascript .
Initialy in the server side everithing was inside a function but request.form sent empty string when I click on submit button. When I click second time everiting was fine. I want to remove this second click.Thus in the client side I removed call to the function and in the server side I removed 'function' and 'end function' .
0
 
jkna_gunnCommented:
i didnt think you could access the window object when running javascript on the server, since the window object is a client side thing.
0
 
COBOLdinosaurCommented:
You cannot do a response back like that.  Only client side scripting can dynamically modify the page, all you end up sending back to the browser is a string that it might recognize as HTML and attempt to render, but at that point the page is badly broken and invalid.

Trying to dynamically generate client side scripting is one thing but trying to control client dynamics from the server is not going to happen.  Generate a valid response page and send it back. cient side function have to be inside script tags.

Cd&
0
 
AzBukaAuthor Commented:
Thank you for your comments. Seems this will be a tough one. Actulally it is possible to generate table in the server running VBScript and send it back to the client running javascript and render it there. The call should be INSIDE javascript function. As I said before it works but requires 2 clicks that is annoying and unacceptable.Will not work if we use POST or GET.
If we can go around this problem. Is it possible to send Javascript variables or inputs from the form and submit them to the VBfunction on the server  before POST or GET. Last night I found 2 solutions for Remote Scripting. They presented a code but this is far beyond my comprehension.
I need something more trivial . I need to send for instance user and passwords input to the server VB function before POST or GET. I think this will solve the problem.Any code ideas?

0
 
AzBukaAuthor Commented:
I am sending web links that I found about Remote Scripting(accessing the server and exchange data without POST or GET.

First Link:
http://www-106.ibm.com/developerworks/web/library/wa-exrel/

Second link:
http:// www.learnasp.com/learn/remotescripting.asp

The second solution looks more easy but I still cannot make it to work for me. I need to send user input from the form from INSIDE Javascript function to the server FUNCTION. Server is running VBScript.
OR
if I don't use Remote scripting how with post or get to call javascript from the server.
THKS
0
 
AzBukaAuthor Commented:
There should be some way to on the client side running on javascript to send user input to the server running on VBScript. Based on input on the server appropriate database to be opened and the information to be displayed in table form. Any ideas?
0
 
AzBukaAuthor Commented:
Nothing is impossibe!
I found a solution by myself. Just write cookies on client side + submit() before post. Then  read coockies and send input to the server. Now I am getting values and processing on the server then create table there and send it back to the client where javascript renders the table.
I would like to allocate 30 points to Cobol for his good comment about client side security issue. The rest of the points I would like to credit myself to use for my next question.
THKS
0
 
COBOLdinosaurCommented:
Thanks AzBuka and Sean.

BTW, I got number 6, a little earlier today. :^)

Cd&
0
 
seanpowellCommented:
That's fantastic Cd&...
A much more exclusive group of experts if you ask me :-)

Well Done.
0
 
COBOLdinosaurCommented:
There are 15 of us. :^)  I guess I am going to have to start answering in XML to get #7.

Cd&
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.