Solved

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

Posted on 2004-04-18
16
620 Views
Last Modified: 2010-04-06
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?
0
Comment
Question by:AzBuka
  • 5
  • 5
  • 2
  • +2
16 Comments
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 10853828
try:

Response.Write "<script language='Javascript'> window.document.writeln('hello world..') </script>"
0
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 10853832
or if it's only to display the value, you can always try like:

Response.Write "hello world.."
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 10853956
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:AzBuka
ID: 10854151
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
 
LVL 6

Expert Comment

by:jkna_gunn
ID: 10867635
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
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 10869674
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
 

Author Comment

by:AzBuka
ID: 10874333
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
 

Author Comment

by:AzBuka
ID: 10877395
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
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 30 total points
ID: 10880337
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
 

Author Comment

by:AzBuka
ID: 10904790
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
 

Author Comment

by:AzBuka
ID: 10909978
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
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 10913521
Thanks AzBuka and Sean.

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

Cd&
0
 
LVL 31

Expert Comment

by:seanpowell
ID: 10913730
That's fantastic Cd&...
A much more exclusive group of experts if you ask me :-)

Well Done.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 10913793
There are 15 of us. :^)  I guess I am going to have to start answering in XML to get #7.

Cd&
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question