HTML,Updated,3232001,code,will,allow,build,in
Quick Search for:  in language:    
HTML,Updated,3232001,code,will,allow,build,in
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 144,429 lines
 Jobs: 168 postings

 
Sponsored by:

 

You are in:

 
Login


 

 


Latest Code Ticker for ASP/ VbScript.
Click here to see a screenshot of this code!Ping in ASP
By Michele_Garneri on 10/28

(Screen Shot)

Embed Real Player Object
By Ziae Mousavi m. on 10/27


Set Country --> Combobox
By Hohl David on 10/27


Client Side Sorting of records
By Ravi Rajan on 10/26


Recordset paging with images
By Ravi Rajan on 10/26


Click here to see a screenshot of this code!Online photo catalogue VBScript 2.1
By Ivan Loire on 10/26

(Screen Shot)

GPS 1.4 WYSIWYG
By Guo Xu on 10/25


Click here to see a screenshot of this code!A Network Monitor tool from ActivXperts Software Inc.
By Freddy Hofstadt on 10/25

(Screen Shot)

Socket samples based on Winsock, TCP/IP and client/server communication
By Ronny Bright on 10/25


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

Building an Input Form Dynamically From a Database.

Print
Email
 

Submitted on: 3/22/2001 1:46:23 AM
By: Joshua i. Lopez 
Level: Beginner
User Rating: By 21 Users
Compatibility:ASP (Active Server Pages)

Users have accessed this article 28894 times.
 
 
     Updated 3/23/2001 11:17 PM !!!!!!!!!!!!!!!!!!!!! This code will allow you to build an input form "on the fly" from a database. Instead of creating and hard coding the same old input form you can automatically build your form based on column names or values in your database! Just added is another page that will submit your data to your database "on the fly", truely making the process of creating web based entry forms DYNAMIC!!!!!!!! Now whenever you have to alter your input forms you just have to change your SELECT statement, no more HTML!! Please vote for this code if you find it useful, and feel free to send me any questions you have regarding the code. Thank you.

This article has accompanying files
 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.

This is the first of 2 Pages you will need...

<html>
<body>
<Form Name="Form" Type="Submit" Method="Post" Action="dynamic2.asp">


<%
<!--~----- Dim Your Variables -----~-->
Dim MyConn, SQL, RS, i

<!--~----- Create the Connection and Open the Connection to the Database -----~-->
<!--~----- This Will Connect to a MS-SQL Database -----~-->
<!--~----- To Connect to an Access Database Replace the Bottom 3 Lines of Code with either... -----~-->
<!--~----- MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; -----~--> 
<!--~----- DBQ=C:\Databases\demo.mdb" -----~-->
<!--~----- or -----~-->
<!--~----- MyConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data -----~--> 
<!--~----- Source=C:\Databases\demo.mdb" -----~-->
<!--~----- or -----~-->
<!--~----- MyConn.Open DSN_Name -----~-->
Set MyConn=Server.CreateObject("ADODB.Connection")
Myconn.ConnectionString = "Provider=SQLOLEDB; Data Source=
Your SQL Server; Initial Catalog=Your Database; User ID=Your Login; Password=Your Password"
Myconn.open

<!--~----- Wriye your SQL statement -----~-->
<!--~----- In this case we have 2 SQL statements because I have a different value for my form fields other than its name -----~-->
<!--~----- If your checkbox/text field will have the same name and value you can safely remove from "SQL1 = "Select" down -----~-->
SQL = "Select
Column Name(s) in your Database that holds values that will become the checkbox/textfield name From Your Table Name"
Set RS = MyConn.Execute(SQL)
SQL1 = "Select
Column Name in your Database that holds values that will become the checkbox/textfield value From Your Table Name"
Set RS1 = MyConn.Execute(SQL1)

<!--~----- Read All of the Records with EOF -----~-->
While not RS.EOF

<!--~----- Build Your Checkboxs -----~-->
<!--~----- You Can Also Build Text Fields by Modifying the Second Line to Read -----~-->
<!--~----- Response.Write rs.fields(intCol).Value & ": <input type=Text size=15 name=" & rs.fields(intCol).Value & "><br>" & vbcrlf -----~-->
<!--~----- If you want the checkboxs or text fields to display column names instead of data values replace any .Value with .Name -----~--> 
<!--~----- Example -----~-->
<!--~----- Response.Write rs.fields(intCol).Name & ": <input type=checkbox name=" & rs.fields(intCol).Name & " value=" & rs.fields(intCol).Name & "><br>" & vbcrlf -----~-->
<!--~----- Also, if your SQL select statement only had one line (same name/value for checkbox/textfields) the following lines of code would read... -----~--> 
<!--~----- For i = 0 to RS.fields.count - 1 -----~-->
<!--~----- Response.Write RS.fields(i).Value & ":<input type=checkbox name='" & RS.fields(i).Value & "' value=" & RS.fields(i).Value & "><br>" & vbcrlf -----~-->
<!--~----- RS.MoveNext -----~-->
For i = 0 to RS.fields.count and RS1.fields.count - 1
Response.Write RS.fields(i).Value & ":<input type=checkbox name='" & RS.fields(i).Value & "' value=" & RS1.fields(i).Value & "><br>" & vbcrlf
RS.MoveNext
RS1.MoveNext
Next
Wend


RS.Close

RS1.Close
MyConn.Close
Set RS = Nothing

Set RS1 = Nothing
Set MyConn = Nothing

%>

<br>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

 

Name this page dynamic1.asp

 

 

Now we create the page that will insert our data into your database

 

<html>
<body>


<%

Dim MyConn, MySQL, rs, i

Set MyConn=Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
MyConn = "Provider=SQLOLEDB; Data Source=
Your SQL Server; Initial Catalog=Your Database; User ID=Your SQL Login; Password=Your Password"
MYSQL = "SELECT
Column Name you want data entered into FROM Your Table Name"
rs.Open MySQL, MyConn, 1, 3

%>

<%

for i = 1 to Request.form.count -1
rs.addnew
rs.Fields("
Column Name you want data entered into") = Request.form(i)
Next
rs.update
Response.Write "Thank you"

%>

</body>
</html>

 

Name this page dynamic2.asp

 

Vote for me if you find this useful, let me know if you need any help with the code!!!

winzip iconDownload article

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzipto decompress it.

Virus note:All files are scanned once-a-day by Planet Source Code for viruses,but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:
1)Re-scan downloaded files using your personal virus checker before using it.
2)NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this article(in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
3/22/2001 4:50:59 AM:Kayhan Tanriseven
very useful code you have!! thanks for submitting!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/22/2001 6:32:30 AM:Rax
nice clean code at last :/
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/22/2001 8:06:04 PM:May
This is very useful. I'm an asp student. I couldn't get your demo.mdb. Also I did not understand all the code. How can I call this dynamic_form.asp, and how it works. Would you like tell me more about this function page.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/23/2001 1:18:57 AM:Lorie Perrish
Excellent code, I have been looking for something that does this for a long time!!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/23/2001 10:57:19 AM:Doug Gaede
Do you have an example database for use with this code?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/28/2001 12:51:04 PM:wicked
what you mean ..
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/28/2001 12:51:28 PM:WICKED
what you mean .. wow can't believe this is not out there already you can use this same coding for oracle ,sql or even in a email I been offering fastemailer.asp for along time that does this. wow just cant believe this wasn` t out there already. anyway nice job for posting it for others.Guess I goes to show you can never realy be sure of whats posted.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
4/3/2001 8:18:05 AM:africa
Hi, Your code did wonders for me and I'd give it 5 out of 5 any day! Please keep sending more of your new code and keep vbscript/asp alive!!!!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
4/7/2001 8:13:11 PM:John
Can you show me how to make your dynamic code work with 60 dropdown box... I am new to ASP.. Thanks My e-mail: jhmai@eudoramail.com
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/15/2001 3:44:57 PM:SVM
Hey, sorry to bother you, but is there a way to use this code to submit a form remotely?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/11/2001 6:12:51 PM:RLF
Where can you get the Demo.mdb. It was not in the download
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/31/2001 5:31:41 PM:yogi
This code is very useful. But, can we add validations or business rules dynamically ?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this article has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular article, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.