Solved

Accessing FORMs data

Posted on 1998-07-16
8
178 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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
 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

810 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