Forum Moderators: open

Message Too Old, No Replies

ASP question

ASP object scope

         

ken4runner

4:30 pm on Nov 17, 2004 (gmt 0)

10+ Year Member



I am working on an ASP page, and I am having trouble accessing objects (for example text fields in a form) in the webpage from within the VB script code.

example 1:
---------------------------------------------------
<html>

<form action="my.asp" method=POST name="form1">
<INPUT type="text" name="EmployeeID" size="14">
</form>

<%
'vb code here
Dim EID
EID = document.form1.EmployeeID.value

%>

</html>

---------------------------------------------------
for the example 1 page, I am getting the following error message in the browser:

Microsoft VBScript runtime error '800a01a8'
Object required: ''

In a VBscript sub routine on a regular webpage, I can access webpage objects in that page all day long.

example2:
-------------------------------------------
<html>
<SCRIPT LANGUAGE="VBSCRIPT">
Sub btn_onclick()
document.form1.EmployeeID.value = "12345"
checkme = document.form1.EmployeeID.value
MsgBox "The Employee ID is " & checkme & " ",0,"VBScript Example"
End Sub
</SCRIPT>

<form action="my.asp" method=POST name="form1">
<INPUT type="text" name="EmployeeID" size="14">
</form>

</html>

---------------------------------------------------

example2 works great.

I have done some research and I can’t seem to find a way to make what I am trying to do in example1 work.

It has something to do with scope, any thing I create in the VB script code I can work with in that code, (I can create and write out a form from within the VBcode and assign values to it) but the elements of the webpage that are outside the vbscript code I cant get to to save my life.

Any guidance on this would be greatly appreciated.

thanks -

mattur

4:43 pm on Nov 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Aplogies if I've misunderstood your question Ken4, but it seems you are trying to use client side vbscript references on a server side script.

To pick up the value of the EmployeeID text box in a server side ASP page use:

<%
Dim EID
EID = Request.Form("EmployeeID")
%>

HTH

ken4runner

4:51 pm on Nov 17, 2004 (gmt 0)

10+ Year Member



Thanks HTH,

I don't have any problem getting data from the form once it has been submitted, via the request object like you mentioned...

I am trying to update a field in the form with data I look up from the db in the vbcode... (see example1). I want to write a value into the form field based on what I look up in the vb code.

thanks for your reply.

mattur

5:26 pm on Nov 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So you're using server side ASP to query a database, and then you want to set the value of a form element with client side vbscript to the value returned from the db? Is that correct? Do you need client side script? Sorry for being obtuse, just trying to get a handle on what you want to achieve.

ken4runner

5:39 pm on Nov 17, 2004 (gmt 0)

10+ Year Member



you're fine - and pretty close to what I am trying to do.

Example1 is what I want to do, Example2 was what I can do, (but Example2 doesn't help me with the error I get in Example1). If that makes any sense.

I want to use the ASP page to look up a value from the DB, and then I need to put that value in a form on that page. I cant get that to work.

the form is outside of the script, and I cant access it from within the script.

example 1:
---------------------------------------------------
<html>

<form action="my.asp" method=POST name="form1">
<INPUT type="text" name="EmployeeID" size="14">
</form>

<%
'vb code here
Dim EID
EID = document.form1.EmployeeID.value

%>

</html>

---------------------------------------------------

This is what I am trying to do, write the EID value into the form that is outside the script. Wont work. I get a Microsoft VBScript runtime error '800a01a8'
Object required error...

thanks again for your replies.

I am working on a workaround, but I am having to re-code the entire ASP page to get around not being able to update the value in that form.

ken4runner

5:42 pm on Nov 17, 2004 (gmt 0)

10+ Year Member




my code is backwards as to what I described...

In my code above I am trying to read the form value into the code, which also doesnt work.

The case I have been describing would be like this:

document.form1.EmployeeID.value = EID

(trying to set the form value to be equal to the value I look up in the db).

Sorry, I had that backwards. So far, it wont work either way.

mattur

5:57 pm on Nov 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Now I'm really confused ;)

If you just want the textbox to have the db value as a default value, you can use:

<INPUT type="text" name="EmployeeID" size="14" value=""<% = EID %>">

If you want the db value to be inserted by client side script, you could write the EID value into that script directly:

Sub btn_onclick()
document.form1.EmployeeID.value = "<% = EID %>"
...

BTW: HTH = Hope This Helps :)

RossWal

7:38 pm on Nov 17, 2004 (gmt 0)

10+ Year Member



Ken,
If you haven't figured it out, in classic asp you can't reference the form values until the post from the client has occurred. To set the values for display, you need to dynamically build the html as Mattur shows above.

Ross

ken4runner

8:54 pm on Nov 17, 2004 (gmt 0)

10+ Year Member



thanks -

If I get my workaround working, I'll post it...