Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing results from JS to webpage

Status
Not open for further replies.

timmbo

Programmer
Feb 22, 2001
167
US
Hi All,

I need to return the results of my JS file to my webpage. How would I return myTwoMonths, myThreeMonths and myFourMonths to replace the static months?


function setMonths(_form) {

var tMonth = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

var currDate = new Date();

//Getting current month. For Pooled Sweep it's two months prior to
//current month.
var twoPriorMonths = currDate.getMonth()-2;
var myTwoMonths = tMonth[twoPriorMonths];

//Getting second month. Three months prior to current month.
var threePriorMonths = currDate.getMonth()-3;
var myThreeMonths = tMonth[threePriorMonths];

//Getting third month. Four months prior to current month.
var fourPriorMonths = currDate.getMonth()-4;
var myFourMonths = tMonth[fourPriorMonths];
}



Following is my HTML:


<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<HTML>
<HEAD>

<META http-equiv=&quot;Content-Type&quot;
content=&quot;text/html; charset=WINDOWS-1252&quot;>
<META name=&quot;GENERATOR&quot; content=&quot;IBM WebSphere Studio&quot;>
<TITLE>psweep_Report_Archive.jsp</TITLE>
<LINK rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;../service/js/isc-style.css&quot; title=&quot;Standard ISC Style&quot;>
<SCRIPT language=&quot;JavaScript&quot; src=&quot;../service/js/archive_dates.js&quot;></SCRIPT>
</HEAD>
<BODY onload=&quot;javascript:setMonths('rptPooledSweepArchiveForm');&quot;>
<FORM name=&quot;rptPooledSweepArchiveForm&quot; action=&quot;../isc/PooledSweepServlet&quot;>
<BR>
<BR>
<TABLE border=&quot;0&quot; align=&quot;center&quot; width=&quot;170&quot;>
<TBODY>
<TR>
<TH align=&quot;middle&quot;><FONT size=&quot;2&quot;><b>Archive Reports</b></FONT></TH>
</TR>
<TR>
<TD> </TD>
</TR>
<OL>
<TR>
<TD><LI>June</LI></TD>
</TR>
<TR>
<TD><LI>May</LI></TD>
</TR>
<TR>
<TD><LI>April</LI></TD>
</TR>
</OL>
</TBODY>
</TABLE>
</FORM>
</BODY>
</HTML>


Thanks for your help.

Tim
 
Presumably &quot;June&quot; is to be replaced with myTwoMonths, &quot;May&quot; with myThreeMonths, and &quot;April&quot; with myFourMonths. This always being the case, surround June/May/April with anchor tags with only a name attribute:
Code:
<A NAME=replace2m>June</A>
...
<A NAME=replace3m>May</A>
...
<A NAME=replace4m>April</A>
...
then, after the variables are loaded in your Javascript function:
Code:
replace2m.innerHTML = myTwoMonths;
replace3m.innerHTML = myThreeMonths;
replace4m.innerHTML = myFourMonths;

That's for IE. I think in Netscape you need to say innerText (if I remember correctly from a previous poster on a previous topic).

'hope that helps.

--Dave
 
Thanks for the help Dave. I'll give it a shot.

Tim
 
P.S., I forget whether anchors require the form name in front of them (e.g., formName.anchorName.innerHTML=...) or not. If one way doesn't work, try the other.

--D
 
Here is a Javascript function which can deal with the (IE), Netscape(NN) and Mozila(MO) differences:

function ChangeContent(id, str) {
if (type==&quot;IE&quot;) {
document.all[id].innerHTML = str;
}
if (type==&quot;NN&quot;) {
document.layers[id].document.open();
document.layers[id].document.write(str);
document.layers[id].document.close();
}
if (type==&quot;MO&quot;) {
document.getElementById(id).innerHTML = str;
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top