Solved

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

Posted on 2004-04-18
16
603 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 49

Expert Comment

by:Ryan Chong
Comment Utility
try:

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

Expert Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
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
 

Author Comment

by:AzBuka
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:AzBuka
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks AzBuka and Sean.

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

Cd&
0
 
LVL 31

Expert Comment

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

Well Done.
0
 
LVL 53

Expert Comment

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

Cd&
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Forbidden errors 5 107
Format results with PHP 3 61
Create 4 <div> below each other in php 2 46
jQuery Date picker not working 16 71
Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now