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!

pass javascript var to asp variable

Status
Not open for further replies.

mafenn

IS-IT--Management
Aug 27, 2015
4
US
Hello. I'm new to the forum. I'm updating a page someone else wrote; the function works on the old page but not the new page. I have done much work combining asp and javascript so I'm a little lost here.

On the first page there is a calendar control where the users picks a date.

Code:
    <td align="Left"><input name="EffDate" id="DPC_date1" onfocus="showmydatepickercontrol(this);" type="text" style= "<%response.write StyleRequired%>"></td>

There is some javascript at the top of the page that adds 1 day to the date selected.

JavaScript:
function setTermNotice(tb) {
	var str = tb.value;			// date is MM/DD/YYYY
	var sd = str;
	var d = new Date(sd);
	with (d) {
		setDate(getDate() + 1 );	
	}
	var sMonth = d.getMonth() + 1;		 
	sMonth = "" + sMonth;
	var sDay = d.getDate() + "" ;		
	if (sMonth.length == 1)
	{
		sMonth = "0" + sMonth;		//zero fills month if less than 2 characters
	}
	if (sDay.length == 1)			//zero fills day if less than 2 characters
	{
		sDay = "0" + sDay;
	}
	var mySpan = document.getElementById('sTermDate');
	if (mySpan)
	{ mySpan.innerHTML = sMonth + "/" + sDay + "/" + d.getFullYear(); }
	var mytp1 = document.getElementById('TermDatePlus1');
	if (mytp1)
	{ mytp1.innerHTML = sMonth + "/" + sDay + "/" + d.getFullYear(); }
}

Below the calendar, where the user selects the initial date, is some asp code that displays the new date ('sTermDate'). The new date does show up here. I've substituted 'TermDatePlus1' for 'sTermDate' and it still shows up so I know they are both populated.

Code:
TermNotice = "All new enrollments will be effective <span id='sTermDate'>00000000</span>"

I also need to get this date ('TermDatePlus1') into a variable that gets submitted to the next page for processing. The new date is put into a hidden variable and a Request.QueryString and sent to the next page where it's picked up by a dictionary object.

HTML:
<input type="hidden" name="TermDatePlus1" value="">

Code:
dtEffDate = Request.QueryString("TermDatePlus1")

next page:
Code:
Set d=Server.CreateObject("Scripting.Dictionary")
d.add "dteffdate",dteffdate

When it gets to the next page the variable is blank. I have a response.write dteffdate and it is always blank.

Code:
response.write dteffdate 
response.end

Any help would be appreciated!

 
blank. I have a response.write dteffdate and it is always blank.


That's because "dteffdate" is not a variable, it is a dictionary item you you have to reference it as such.


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Thanks for the reply Chris.

That is odd because I can response.write any other item in the dictionary and get the correct response.

Code:
response.write strsubmitgroupid

Code:
d.add "strsubmitgroupid",strsubmitgroupid

strsubmitgroupid is a field displayed on the first page and put into a querystring also.

Code:
<td align="Left"><input type="text" name="SubmitGroupNum" value="<%response.write strSubmitGroupID>">
Code:
 strSubmitGroupID = Request.QueryString("SubmitGroupNum")

Why does dteffdate work differently? The only difference I see is that dteffdate is a hidden field and strsubmitgroupid was actually displayed on the page.
 
Do you actually pass the variable and reset it's value on "the next page" because I don't see any code that would do that.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
I'm not sure what you mean by "reset it's value"?

The first page shows a pending transaction and has 3000+ lines on it and it displays all of the data for the user to review. The "next page" is the action page and is about 1100 lines and just does processing. Basically it reads through the dictionary, pulls out the values it needs, submits the data to a SQL table and creates a text file with the data. It will tell the user it's been processed and they can move on to the next transaction. Since they are so large I don't really want to post them here.
 
To have a variable that passes from 'page to page' you must have some method of storing the value at P1 and a method of reading the value and initialising the value on P2.
From the code here you store "dteffdate" in the dictionary object on P1 and I am assuming that you then store the dictionary object in a session variable so P2 can retrieve it as an object and read the values.

If that is so, do you also create a variable "dteffdate" on P2 and set it to the value that is stored in d.item("dteffdate")?

Or are these variables initialised as 'global' and "included" in all the scripts?


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
This bit of the programming was done by someone else; who is no longer around. Not everything he did makes sense to me. All of the variables are stored in querystrings on the first page. The dictionary is on the second page. We aren't using session variables with this project and all variables are local.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top