Online Shopping : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

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

Entry

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">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-
1">
<script language="JavaScript" id="loadScript">
</script>
</head>
<body>
<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';
  script.id = 'loadScript';
  head.appendChild(script)
  text.value=x;
}
</script>
<input type="button" onClick="getJS()" value="Get The JS !">
<br>Time:<input name="text" type="text">
</body>
</html>
____________________________________________
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 !
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com