[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

Invoking XMLHttp object from Javascript to update data in SQLServer database

Asked by countrymeister in Active Server Pages (ASP), JavaScript

Tags: data, asp, function, javascript, update

I have an ASP page called Occupnats with a button called Edit for each row of Occupants,
when the button is clicked I display another asp page called Occupant Details, which has two fields and two buttons OK and Cancel

The user can change the value of the fields , and click OK, which in turn should save the changes to the database.
I am using the XMLHttp object from my javascript function but it gives me an 500 Internal Server error.
Here is my code

Occupants page
--------------------------

Javascript function
function Edit(id)
      {
            
            var h,w
            h = screen.height
            w = screen.width
            var l,t
            l = parseInt((w-300)/2)
            t = parseInt((h-160)/2)            
            var winpop = window.open('occupant_data_dates.asp?Enabled=1&RBOID=' + id,'HD' + id,'toolbar=no,location=no,menubar=no,dependent,scrollbars=no,width=450,height=140,left='+l+',top='+t);
            winpop.focus();
      }

here is the button click event code

Response.Write "<td><span id=""r_" & row_count & "c_3a""><input type=""button"" name=""add_occupant_"" value=""Edit"" class=""button3"" OnClick=""Edit('" & rsGetData("ID") & "')""></span></td>"
===============================================================================
Occupant Details page
----------------------------

Onclick event for OK button
<input type="button" value="OK" name="OK" class="buttonNormal"  onClick="validateForm(<%Response.Write d_RoomBlockOccupantID%>);" >

Validate form javascript functions
<script language="JavaScript" type="text/javascript">
      
      var _xmlHttp=null;
      var RBOID=0;
      var ArrivalDate="";
      var DepartureDate="";
      var SpecialNeeds="";

function validateForm(id)
      {
        AddUpdateRBOID(id);
        return true;
      }
      
function AddUpdateRBOID(id)
      {
            RBOID=id;
            ArrivalDate=document.forms[0].elements['ArrivalDate'];
            DepartureDate=document.forms[0].elements['DepartureDate'];
            SpecialNeeds=document.forms[0].elements['SpecialNeeds'];
            DB();
            window.close();
      }
      
function DB()
      {
            var result="";
            _xmlHttp=getXMLHTTP();
            var sURL = "occupant_data_dates_update1.asp?rboid=" + RBOID + "&ad=" + ArrivalDate + "&dd=" + DepartureDate + "&sneeds=" + SpecialNeeds;            
            _xmlHttp.open( "POST", sURL, false );
            _xmlHttp.send(null);
            var TempString=_xmlHttp.responseText;
            var Tempstatus = _xmlHttp.status;
            var TempstatusText = _xmlHttp.statusText;
            var temp_array=TempString.split(",");
            result=temp_array[0];
            message=temp_array[1];
            if(result=="0")
            {
            
            }else{
                        if(message==undefined)
                        {
                              alert(TempString);
                              
                        }else{
                              alert(message);
                              alert(Tempstatus);
                              alert(TempstatusText);
                              alert(result);
                              
                        }
                        
                  return false;
            }

            return true;
      }
function getXMLHTTP()
      {
            // returns an XMLHttp object... gets it in an IE/Mozilla friendly way..
            var A=null;
            try
            {
                  A=new ActiveXObject("Msxml2.XMLHTTP")
             }catch(e){
                  try
                  {
                        A=new ActiveXObject("Microsoft.XMLHTTP")
                  }catch(oc){
                        A=null
                  }
            }

            if(!A && typeof XMLHttpRequest != "undefined")
            {
                        A=new XMLHttpRequest()
            }
            return A
      }
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
<%@ Language=VBScript %>
<%
Option Explicit
If Session("UserID")="" OR Session("Password")="" Then
	Response.Write "<script>"
	Response.Write "parent.ChildTimeOut();"
	Response.Write "</script>"
	Response.End
End If
%>
<!--#include file ="Includes/housing_db_connect.asp"-->
<!--#include file ="Includes/encrypter.asp"-->
<%
dim strSQL
dim rsGetData
dim Action
dim Name
dim ArrivalDate
dim DepartureDate
dim SpecialNeeds
 
dim d_RoomBlockID
dim d_RoomBlockOccupantID
dim d_ViewEnabled
 
 
dim txtDis
dim btnDis
 
d_RoomBlockOccupantID=request.querystring("RBOID")
d_ViewEnabled=request.querystring("Enabled")
 
If d_ViewEnabled=1 Then		
		txtDis = " enabled"
		btnDis = " enabled"
Else		
		txtDis = " readonly"
		btnDis = " disabled"	
end if
 
 
 
 
strSQL="exec spOccupantData_LoadPopup " & d_RoomBlockOccupantID 
Set rsGetData=adocon.Execute(strSQL)
	If NOT rsGetData.EOF Then
		Name=rsGetData("Name")
		ArrivalDate=rsGetData("ArrivalDate")
		DepartureDate=rsGetData("DepartureDate")
		SpecialNeeds=rsGetData("SpecialNeeds")
	
	Else
		Name=""
		ArrivalDate=""
		DepartureDate=""
		SpecialNeeds=""
	End If
 
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>Occupant Details</title>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<meta name="author" content="AB">	
	<meta name="date-created" content="2007-12-23">
	<meta name="robots" content="noindex,nofollow">
	<meta http-equiv="msthemecompatible" content="no">
	<link rel="stylesheet" href="Style/style.css" type="text/css">
 
	<script language="JavaScript" type="text/javascript">
	
	var _xmlHttp=null;
	var RBOID=0;
	var ArrivalDate="";
	var DepartureDate="";
	var SpecialNeeds="";
	
	function validateForm(id)
	{
		if(!hasText('ArrivalDate','Arrival Date')){
			return false;
		}
		if(!isDate('ArrivalDate','Arrival Date')){
			return false;
		}
		if(!hasText('DepartureDate','Departure Date')){
			return false;
		}
		if(!isDate('DepartureDate','Departure Date')){
			return false;
		}
		if (!compareDate('ArrivalDate','DepartureDate'))
			{ 
			  return false;	
			}
	  AddUpdateRBOID(id);
	  return true;
	}
	
	function AddUpdateRBOID(id)
	{
		RBOID=id;
		ArrivalDate=document.forms[0].elements['ArrivalDate'];
		DepartureDate=document.forms[0].elements['DepartureDate'];
		SpecialNeeds=document.forms[0].elements['SpecialNeeds'];
		DB();
		window.close();
	}
	
	function DB()
	{
		var result="";
		_xmlHttp=getXMLHTTP();
		var sURL = "occupant_data_dates_update1.asp?rboid=" + RBOID + "&ad=" + ArrivalDate + "&dd=" + DepartureDate + "&sneeds=" + SpecialNeeds;		
		_xmlHttp.open( "POST", sURL, false );
		_xmlHttp.send(null);
		var TempString=_xmlHttp.responseText;
		var Tempstatus = _xmlHttp.status;
		var TempstatusText = _xmlHttp.statusText;
		var temp_array=TempString.split(",");
		result=temp_array[0];
		message=temp_array[1];
		if(result=="0")
		{
		
		}else{
				if(message==undefined)
				{
					alert(TempString);
					
				}else{
					alert(message);
					alert(Tempstatus);
					alert(TempstatusText);
					alert(result);
					
				}
				
			return false;
		}
 
		return true;
	}
	
	
	function hasText(strFieldName,strMessage)
	{
		var objFormField = document.forms[0].elements[strFieldName];
		var strValue = objFormField.value;
		strValue = strValue.split(" ").join("")
		if(strValue.length<1){
			alert("The value for " + strMessage + " cannot be blank!");
			objFormField.focus();
			return false;
		}
		if(strValue.length>10){
			alert("The value for " + strMessage + " is invalid!");
			objFormField.focus();
			return false;
		}
		return true;
	}
	
	function isDate(strFieldName,strMessage)
	{
		var objFormField = document.forms[0].elements[strFieldName];
		strDate = objFormField.value;
		if(strDate.length>0){
				var dateregex=/^[ ]*[0]?(\d{1,2})\/(\d{1,2})\/(\d{4,})[ ]*$/;
				var match=strDate.match(dateregex);
				if (match){
						    var tmpdate=new Date(match[3],parseInt(match[1],10)-1,match[2]);
					if (tmpdate.getDate()==parseInt(match[2],10) && tmpdate.getFullYear()==parseInt(match[3],10) && (tmpdate.getMonth()+1)==parseInt(match[1],10)){ 
						return true; 
					 }
				  }
			alert("Please enter a valid " + strMessage + "!");
			objFormField.focus();
			return false;
		}
		else{
			 return true;
		}
	}
	
	function compareDate(strArrivalDate, strDepartureDate)
         {
        
         var fromDate = document.forms[0].elements[strArrivalDate];
         strFromDate = fromDate.value;
         var ToDate = document.forms[0].elements[strDepartureDate];
         strToDate = ToDate.value;
         
         var first=new Date(strFromDate);
		 var second=new Date(strToDate);
		 if (first>second)
		 {
			alert("Arrival date must be less than Departure date");			
			return false;
		 }
            return true;
         }
 
	function getXMLHTTP()
	{
		// returns an XMLHttp object... gets it in an IE/Mozilla friendly way..
		var A=null;
		try
		{
			A=new ActiveXObject("Msxml2.XMLHTTP")
		 }catch(e){
			try
			{
				A=new ActiveXObject("Microsoft.XMLHTTP")
			}catch(oc){
				A=null
			}
		}
 
		if(!A && typeof XMLHttpRequest != "undefined")
		{
				A=new XMLHttpRequest()
		}
		return A
	}
 
	function SetInnerHTML(span_id, str_text)
	{
		eval("document.getElementById('" + span_id + "').innerHTML=str_text");
	}
	
	function ChildTimeOut()
	{
		parent.ChildTimeOut();
	}
	</script>
</head>
<body>
<form name="occupant_data_dates" action="occupant_data_dates.asp" method="post" AUTOCOMPLETE="off">
<!-- OCUPANT DATA DETAILS TABLE-->
<table  height="100%" width="450" cellpadding="0" cellspacing="0" border="0">	
    <tr>
		<td><img src="Images/tran_pix_1x1.gif" width="5" height="1" border="0" alt=""></td>
		<td><span class="Label2"><% Response.Write Name%></td>
		<td><span class="Label1">&nbsp;</td>		
		<td><span class="Label1">&nbsp;</td>
		<td><span class="Label1">&nbsp;</td>
		<td><img src="Images/tran_pix_1x1.gif" width="1" height="1" border="0" alt=""></td>
	</tr>		
	<tr>
		<td><img src="Images/tran_pix_1x1.gif"  width="5" height="1" border="0" alt=""></td>
		<td><span class="Label1">Arrival Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</td>
		<td>
			<input type="text" id="ArrivalDate" name="ArrivalDate" class="textbox1" value="<% Response.Write ArrivalDate%>" <%Response.Write txtDis%> >&nbsp;&nbsp<span class="Label1">mm/dd/yyyy</span>	
		</td>
		
		
	</tr>
	<tr>
		<td><img src="Images/tran_pix_1x1.gif"  width="5" height="1" border="0" alt=""></td>
		<td><span class="Label1">Departure Date :</td>
		<td>
		<input type="text" id="DepartureDate" name="DepartureDate" class="textbox1" value="<% Response.Write DepartureDate%>" <%Response.Write txtDis%> >&nbsp;&nbsp<span class="Label1">mm/dd/yyyy</span>
		</td>
		
				
	</tr>
	<tr>
		<td><img src="Images/tran_pix_1x1.gif"  width="5"  height="1" border="0" alt=""></td>
		<td><span class="Label1">Special Needs&nbsp;&nbsp;&nbsp;:</td>
		<td>
		<textarea name="SpecialNeeds" id="SpecialNeeds" <%Response.Write txtDis%> style="width: 100%; class: Label1;" ><%Response.Write SpecialNeeds%></textarea>		
		</td>
	</tr>
	<tr>
		<td><img src="Images/tran_pix_1x1.gif"  width="5"  height="1" border="0" alt=""></td>
		<td><span class="Label1">&nbsp</td>
		<td><span class="Label1">&nbsp</td>
	</tr>
	<tr>
		<td><img src="Images/tran_pix_1x1.gif"   width="5" height="1" border="0" alt=""></td>
		<td><span class="Label1">&nbsp;</td>				
		<td align="left">
			<input type="button" value="OK" name="OK" class="buttonNormal"  onClick="validateForm(<%Response.Write d_RoomBlockOccupantID%>);" <%Response.Write btnDis%>>&nbsp;&nbsp;
			<input type="button" value="Cancel" name="Cancel" class="buttonNormal" onClick="window.close();">
		</td>
		<td><img src="Images/tran_pix_1x1.gif"  width="1"  height="1" border="0" alt=""></td>		
	</tr>
</table>
<!-- END OCUPANT DATA TABLE-->
</form>
</body>
</html>
[+][-]12/25/07 01:55 AM, ID: 20526851Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Active Server Pages (ASP), JavaScript
Tags: data, asp, function, javascript, update
Sign Up Now!
Solution Provided By: hielo
Participating Experts: 3
Solution Grade: A
 
[+][-]12/24/07 01:01 PM, ID: 20525848Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/24/07 03:20 PM, ID: 20526044Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/24/07 04:32 PM, ID: 20526159Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/24/07 05:47 PM, ID: 20526276Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 / EE_QW_2_20070628