accessing variables 
Author Message
 accessing variables

I am having trouble understanding serverside and client side script.
This is part of the code in the .asp page
When I run this I get error message "rs1 is undefined"
I have tried running ... <Script Language="JavaScript" RUNAT=Server> but I
just get the error "Object expected" referring to the
onChange="mnChange(this.options[selectedIndex].value".
Can anybody help me.

Regards
Steve


<html>
<%
//Create Connection for Machine Name table
var connstr1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath("/Permits/fpdb/Permits.mdb");
var conn1 = Server.CreateObject("ADODB.Connection");
conn1.open(connstr1);
var strSQL = "Select * from Plant Order by Equipment_Title";
var rs1 = conn1.Execute(strSQL);
rs1.moveFirst();

<Script Language="JavaScript">
function mnChange(SelectedOption)
{
var defaultSelected = false;
var selected = false;
var optionName;
var num;

// Changes the Component list box options based on what is selected in the
Machine_Name list
//delete options first
for (num=document.Form1.Component_Name.length-1; num > 0; num--)
 { document.Form1.Component_Name.options[num] = null; }
while (!rs1.EOF)
{ optionName = new Option(rs1("Component").value, rs1("Component").value,
defaultSelected, selected);
document.Form1.Component_Name.options[document.Form1.Component_Name.length]
= optionName;
 rs1.movenext();
 }
</Script>

<select size="1" name="Machine_Name"
onChange="mnChange(this.options[selectedIndex].value)">
<option selected value="Select One">Select One</option>

<select size="1" name="Component_Name">
<option value="Select One">Select One</option>
</select>



Thu, 24 Jul 2003 14:41:15 GMT  
 accessing variables
Hi

You are using server object on the client

<select name="bla">
<%
 while(!rs1.EOF)
        {
         Response.Write("<option value='" + rs1("ID") + "'>" + rs1("bla") +
"</option>");
        rs1.MoveNext();
        }
rs1.Close();
%>
</select>

You can also write out an array to the client, something like so...

<%
var theData = "<script type='text/JavaScript'>var myArr = new Array();";
var c = 0;
while( !rs1.EOF )
      {
       theData += "myArr[" + c++ + "]='" + rs("ID") + "';";
       theData += "myArr[" + c++ + "]='" + rs("bla") + "';";
      rs.MoveNext();
      }
Response.Write( theData + "</script>" );
%>

--
--
--
Best Regards
  Vidar Petursson
 ==============================
   Microsoft Internet, Client, SDK MVP
 ==============================
 http://www.icysoft.com
 http://www.dna.is



  Lead Client / Server / SQL Programmer
 ==============================
  No matter where you go there you are
 ==============================
--

Quote:
> I am having trouble understanding serverside and client side script.
> This is part of the code in the .asp page
> When I run this I get error message "rs1 is undefined"
> I have tried running ... <Script Language="JavaScript" RUNAT=Server> but I
> just get the error "Object expected" referring to the
> onChange="mnChange(this.options[selectedIndex].value".
> Can anybody help me.

> Regards
> Steve


> <html>
> <%
> file://Create Connection for Machine Name table
> var connstr1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
> Server.MapPath("/Permits/fpdb/Permits.mdb");
> var conn1 = Server.CreateObject("ADODB.Connection");
> conn1.open(connstr1);
> var strSQL = "Select * from Plant Order by Equipment_Title";
> var rs1 = conn1.Execute(strSQL);
> rs1.moveFirst();

> <Script Language="JavaScript">
> function mnChange(SelectedOption)
> {
> var defaultSelected = false;
> var selected = false;
> var optionName;
> var num;

> // Changes the Component list box options based on what is selected in the
> Machine_Name list
> file://delete options first
> for (num=document.Form1.Component_Name.length-1; num > 0; num--)
>  { document.Form1.Component_Name.options[num] = null; }
> while (!rs1.EOF)
> { optionName = new Option(rs1("Component").value, rs1("Component").value,
> defaultSelected, selected);

document.Form1.Component_Name.options[document.Form1.Component_Name.length]

- Show quoted text -

Quote:
> = optionName;
>  rs1.movenext();
>  }
> </Script>

> <select size="1" name="Machine_Name"
> onChange="mnChange(this.options[selectedIndex].value)">
> <option selected value="Select One">Select One</option>

> <select size="1" name="Component_Name">
> <option value="Select One">Select One</option>
> </select>



Thu, 24 Jul 2003 20:29:04 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Accessing variables from included js file

2. access variable in window.opener

3. Accessing Variables in Top frame

4. Problem accessing variables in JavaScript

5. accessing variables between windows in explorer

6. Accessing variables from outside of vbscript..

7. Accessing variables from the 'other side' (client/server)

8. Access Session variables from within JScript include file

9. this-keyword and custom objects member variables accessing

10. accessing dorm variables

11. Accessing VBscript variables from javascript in ASP

 

 
Powered by phpBB® Forum Software