Online Shopping : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to
Did You Find This Entry Useful?

10 of 21 people (48%) answered Yes
Recently 4 of 10 people (40%) answered Yes


How do I make a javascript (string) variable refreshe its content from the server ?

Apr 7th, 2008 22:46
ha mo, Marius Enache,

I finaly made it happen (by myself ) !
Here is the test HTML :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-
<script language="JavaScript" id="loadScript">
<script language="JavaScript">
function getJS()
  var head = document.getElementsByTagName('head').item(0)
  var scriptTag = document.getElementById('loadScript');
  if(scriptTag) head.removeChild(scriptTag);
  script = document.createElement('script');
  var date=new Date();
  script.src = "b.jsp?x="+date;
  script.type = 'text/javascript'; = 'loadScript';
<input type="button" onClick="getJS()" value="Get The JS !">
<br>Time:<input name="text" type="text">
And here is the test JSP :
<%@ page contentType="application/x-javascript"%>
 long now=System.currentTimeMillis();
var x="<%=now%>";
it simply returns the date in a jsvascript variable that is written in 
a text box in the html document ! But I`m sure you can think of much 
better utility for this script !