Solved

Accessing FORMs data

Posted on 1998-07-16
8
167 Views
Last Modified: 2010-04-09
Ok, I know It's probably a lame question but still:

How do I access a FORM?

I need to put values read from an SQL database into a form using VBScript but the only function I know of is Request.Form and it doesn't seem to accept input, only output...eg you can't do this:
Request.Form("Name") = "Dennis"

Help...please!!
0
Comment
Question by:Dempa
  • 4
  • 4
8 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 1844641
Supposing you use ASP, and are able to get the necessary data out of the database with a recordset named RS, you can display them in a form like this:

<input type="text" name="name1" value="<%=RS("field1")%>">

or if using a textarea:

<TEXTAREA rows=5 cols=45 name="name2" wrap="physical"><%=RS("field2")%></TEXTAREA>





0
 

Author Comment

by:Dempa
ID: 1844642
I know, but I need to access the form AFTER it's been loaded...

Like this:
<FORM NAME="MyForm" ACTION="sub.asp" METHOD=POST>
<INPUT TYPE=TEXT NAME="Name" SIZE=15 MAXLENGTH=15>
</FORM>

and then I need to set the value to something from a database using VBscript in Active Server Pages, something like this:

Form("Name") = rs.Fields("A_Name")

The question is, how?
0
 
LVL 28

Expert Comment

by:sybe
ID: 1844643
You can change formvalues using javascript

document.form_name.field_name.value = "new value"

The get the values to Javascript, you'll have to get back to the database. So that means that a document needs to be reloaded. This must not necessarily be the document with the form, as Javascript can also change form values in other documents (as long as you know how to find that document (within a frameset or using a new window that is opened)

Another solution is to get all the data you might need to the document the first time and store them in Javascript variables and call those whenever you need them.

Anyway, you'll need some javascript.

I can give you some code if you make clear on what event the form values have to change.

0
 

Author Comment

by:Dempa
ID: 1844644
But...I have to do this in VBScript.

The form values are to be set when the page is _almost_ finished loading....Right after the form is loaded (i.e. after the </FORM> tag) I have a function call:

</FORM>
<% FixValues %>
</BODY>
</HTML>

And this function is supposed to put the values in their right places in the form...

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 28

Expert Comment

by:sybe
ID: 1844645
Don't despair, you can use VBScript in your serverside code, I propose to use javascript client side.

Your VBScript could look like this:


<script>
<%
' code to get make the connection and the recordset
' Server side VBscript writes Client side Javascript here
Response.write "var strField1 = " & RS("field1") & ";"
Response.write "var strField2 = " & RS("field2") & ";"
Response.write "var strField3 = " & RS("field3") & ";"
' the rest is HTML/JavaScript
%>
</script>

<form name="frmAnyName">
<input type="text" name="field1">
<input type="text" name="field2">
<input type="text" name="field3">
</form>

<script>
document.frmAnyName.field1.value = strField1;
document.frmAnyName.field2.value = strField2;
document.frmAnyName.field3.value = strField3;
</script>

What this does is only filling the values of the form when the page is (almost) loaded. Any changes that the user makes before the form fields are filled by Javascript will be overwritten.
0
 

Author Comment

by:Dempa
ID: 1844646
OK. Good enough answer...Post it as an answer and I´ll give you the points..

btw, thanx! :-)
0
 
LVL 28

Accepted Solution

by:
sybe earned 60 total points
ID: 1844647
ok, thanks
0
 

Author Comment

by:Dempa
ID: 1844648
Adjusted points to 60
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now