Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: textField+DB


Message #1 by "M" <mrayess_1980@h...> on Sat, 7 Sep 2002 12:55:37
Hi;
I have a problem..I am developing an application where I have in some page 
textfields generated 
randomly depending on the number of students (it is a query, and while not 
sqlEmp.not eof... generate textfields), the fields take the names: 
std_email1,std_email2,...etc("std_email"&i).. each textfield is followed by a "save" 
image, when the user type the email and click on the image, the email address he 
typed is to be saved in the db..
How can perform this, i.e. updating the db just after he clicks the image??

Regards
Message #2 by Berkay Mese <berkaymese@y...> on Sat, 7 Sep 2002 07:00:31 -0700 (PDT)
This may be accomplished using client side Javascript.

Berkay 

as follows ;
For ex:(

<!-- this part is subject to your modification.
	 It's just for test..I assume
//-->
<% for j = 0 to recordCount%>
  <img onclick="updateDB(this)" name="save<%=j%>">
<%  Next %>

<SCRIPT LANGUAGE=javascript>

<!--
	function updateDB(txtID) {
	try {
		var conn = new ActiveXObject("ADODB.Connection")
		var sqlStr = "update tableName set email='" +
frm1.txtID.value + "'";
		conn.Open connectionString
		conn.BeginTrans(); 
		conn.Execute(sqlStr);
		conn.CommitTrans();
	 }
	 catch(e)
		{
			conn.RollbackTrans();
			document.write(e.message);
			break;
		}
	 }
//-->
</SCRIPT>

--- M <mrayess_1980@h...> wrote:
> Hi;
> I have a problem..I am developing an application
> where I have in some page 
> textfields generated 
> randomly depending on the number of students (it is
> a query, and while not 
> sqlEmp.not eof... generate textfields), the fields
> take the names: 
> std_email1,std_email2,...etc("std_email"&i).. each
> textfield is followed by a "save" 
> image, when the user type the email and click on the
> image, the email address he 
> typed is to be saved in the db..
> How can perform this, i.e. updating the db just
> after he clicks the image??
> 
> Regards


__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com
Message #3 by boryan@s... on Sat, 7 Sep 2002 15:57:39
Dear Berkey.

You wrote:
conn.Open connectionString

Can you please write connectionString line with correct syntax?
I need to connect my access database through Javascript and cann't get 
it...
Something wrong with syntax, so, if you please, I need correct DSN-less 
connection string to anyName.mdb access database...

Thanks in advance

Boris

> This may be accomplished using client side Javascript.

Berkay 

as follows ;
For ex:(

<!-- this part is subject to your modification.
	 It's just for test..I assume
//-->
<% for j = 0 to recordCount%>
  <img onclick="updateDB(this)" name="save<%=j%>">
<%  Next %>

<SCRIPT LANGUAGE=javascript>

<!--
	function updateDB(txtID) {
	try {
		var conn = new ActiveXObject("ADODB.Connection")
		var sqlStr = "update tableName set email='" +
frm1.txtID.value + "'";
		conn.Open connectionString
		conn.BeginTrans(); 
		conn.Execute(sqlStr);
		conn.CommitTrans();
	 }
	 catch(e)
		{
			conn.RollbackTrans();
			document.write(e.message);
			break;
		}
	 }
//-->
</SCRIPT>
Message #4 by Berkay Mese <berkaymese@y...> on Sat, 7 Sep 2002 10:00:15 -0700 (PDT)
Actually,you must not expose your connString in
client-side script, because someone viewing your
source can see the connection string and it's a
hazardous danger.
Instead you may use XMLHTTP object for processing
"save" action in a server-side routine using a
client-side request, as follows..

Berkay

For ex:
'Server-side operations(save to DB,etc..) is
'being done in saveRequest.asp

  <SCRIPT LANGUAGE=javascript>
  <!--
  	function updateDB(txtID) {
         try {
         var sqlStr = 'email=' + frm1.txtID.value ;
         var xmlHttpObj = new
ActiveXObject("Msxml2.XMLHTTP.4.0");
	xmlHttpObj.open("GET","saveRequest.asp?" +
sqlStr,false) ;
  	xmlHttpObj.setRequestHeader("Content-type:",
"text/xml");
	xmlHttpObj.send();
        if (xmlHttpObj.responseText != 0) 
           alert('error occurred');       
        }
        catch(e)
          {
             alert(e.message);
          }
//-->
 </SCRIPT>
   
'saveRequest.asp
' Your db connections, operations
'(save,update,delete,etc..)
' I'm just writing a DSN-Less connection to access DB.
<%
   Dim mail
   Dim conn
   mail = Trim(Request.QueryString("email"))
   Set conn = CreateObject("ADODB.Connection")
   With conn
      .Open  _
   "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" &
_
   "Path of anyName.mdb"
  'Here's your update, save,delete code..
      .execute(sqlstr)
  'etc....
      .BeginTrans()
      If err = 0 Then 
         .CommitTrans()
      Else
         .RollBackTrans
      End If 
   End With   
  conn.close 
  Set conn = Nothing  
  response.write err.number
%>



--- boryan@s... wrote:
> Dear Berkey.
> 
> You wrote:
> conn.Open connectionString
> 
> Can you please write connectionString line with
> correct syntax?
> I need to connect my access database through
> Javascript and cann't get 
> it...
> Something wrong with syntax, so, if you please, I
> need correct DSN-less 
> connection string to anyName.mdb access database...
> 
> Thanks in advance
> 
> Boris
> 
> > This may be accomplished using client side
> Javascript.
> 
> Berkay 
> 
> as follows ;
> For ex:(
> 
> <!-- this part is subject to your modification.
> 	 It's just for test..I assume
> //-->
> <% for j = 0 to recordCount%>
>   <img onclick="updateDB(this)" name="save<%=j%>">
> <%  Next %>
> 
> <SCRIPT LANGUAGE=javascript>
> 
> <!--
> 	function updateDB(txtID) {
> 	try {
> 		var conn = new ActiveXObject("ADODB.Connection")
> 		var sqlStr = "update tableName set email='" +
> frm1.txtID.value + "'";
> 		conn.Open connectionString
> 		conn.BeginTrans(); 
> 		conn.Execute(sqlStr);
> 		conn.CommitTrans();
> 	 }
> 	 catch(e)
> 		{
> 			conn.RollbackTrans();
> 			document.write(e.message);
> 			break;
> 		}
> 	 }
> //-->
> </SCRIPT>


__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

  Return to Index