Ask a Question related to ASP Database, Design and Development.
-
Jeremy #1
populating text from database
I am trying to populate multiple textboxes from an Access database. I
am trying to write code to generate the appropriate number of
textboxes based upon the number of records in the access table. I am
getting lost with the code...Here's what I've got:
<%@ language = "Javascript" %>
<%
var strJob = "";
strJob = Request.Form("txt");
var strconnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:/Inetpub/wwwroot/ITI/fpdb/resume04.mdb";
%>
<script language=Javascript>
function initControls()
{
populateJob();
}
function build() {
var num = 0;
var tbl = "<table border='0'>\n";
for (var i=0; i<10; i++) {
tbl += "<tr>\n";
for (var j=0; j<4; j++) {
tbl += " <td>\n";
tbl += " <input type='radio' name='box' value='Box" +
num
+ "'>\n";
tbl += " </td>\n";
num++;
}
tbl += " <td>\n";
tbl += " <input type='text' name='txt" + num + "'
value=''>\n";
tbl += " </td>\n";
tbl += "</tr>\n";
}
tbl += "</table>\n";
document.write(tbl);
}
function populateJob()
{
<%
var rs = Server.CreateObject("ADODB.Recordset");
var sql = "select distinct Preference from Preferences"
rs.Open(sql,strconnection);
var n=0;
while (!rs.EOF)
{
var stateID = rs.Fields("Preference");
var stateDesc = rs.Fields("Preference");
Response.Write("document.repForm.txt[" + n + "] = new value('" +
stateDesc+ "','" + stateID + "');");
if (new String(strJob).search(stateID) != -1)
Response.Write("document.repForm.txt[" + n + "].selected = true;");
rs.MoveNext();
n++;
}
rs.Close();
%>
}
</script>
<html>
<head>
<title>Resume</title>
</head>
<BODY onload = "initControls();" >
<form method="post" onsubmit="return check()">
<language = "javascript">
BUILD()
</script>
<input type="submit" value="submit">
<input type="reset" value="clear">
</form>
</body>
</html>
Thanks!
Jeremy Guest
-
Populating Drop Down Boxes from a database
We moved our wesite from a Box running Coldfusion 4.0 to a box running Coldfusion MX. We populate some drop down boxes with information from a... -
Web Form Populating Database
Publisher 2003. Web form set to save the data in a comma-delimeted text file on my web server. Form working well, I'm able to use the wizard in... -
Populating three list boxes from the database
Can anybody help? I need to have three list boxes automatically populating each other, (ie when region is selected from the first listbox, it will... -
populating radiobuttonlist from database programmatically
I store radiobuttonlist values in the db using the string value of the radio button item value. (nvarchar) I am creating an edit functionality on... -
Populating another database with records from an asp page.
Apologies for the length of this mail but code is included. Have a page that pulls data from one database & displays the results, using a loop to... -
McKirahan #2
Re: populating text from database
"Jeremy" <jeremy_zifchock@yahoo.com> wrote in message
news:f9d85033.0401060730.182291eb@posting.google.c om...> I am trying to populate multiple textboxes from an Access database. I
> am trying to write code to generate the appropriate number of
> textboxes based upon the number of records in the access table. I am
> getting lost with the code...Here's what I've got:
>
> <%@ language = "Javascript" %>
> <%
>
> var strJob = "";
> strJob = Request.Form("txt");
>
> var strconnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=C:/Inetpub/wwwroot/ITI/fpdb/resume04.mdb";
> %>
> <script language=Javascript>
>
> function initControls()
> {
> populateJob();
> }
>
> function build() {
> var num = 0;
> var tbl = "<table border='0'>\n";
> for (var i=0; i<10; i++) {
> tbl += "<tr>\n";
> for (var j=0; j<4; j++) {
> tbl += " <td>\n";
> tbl += " <input type='radio' name='box' value='Box" +
> num
> + "'>\n";
> tbl += " </td>\n";
> num++;
> }
> tbl += " <td>\n";
> tbl += " <input type='text' name='txt" + num + "'
> value=''>\n";
> tbl += " </td>\n";
> tbl += "</tr>\n";
> }
> tbl += "</table>\n";
> document.write(tbl);
> }
>
> function populateJob()
> {
> <%
> var rs = Server.CreateObject("ADODB.Recordset");
> var sql = "select distinct Preference from Preferences"
> rs.Open(sql,strconnection);
> var n=0;
> while (!rs.EOF)
> {
> var stateID = rs.Fields("Preference");
> var stateDesc = rs.Fields("Preference");
> Response.Write("document.repForm.txt[" + n + "] = new value('" +
> stateDesc+ "','" + stateID + "');");
>
> if (new String(strJob).search(stateID) != -1)
>
> Response.Write("document.repForm.txt[" + n + "].selected = true;");
> rs.MoveNext();
> n++;
> }
> rs.Close();
> %>
>
> }
>
> </script>
>
> <html>
> <head>
> <title>Resume</title>
> </head>
> <BODY onload = "initControls();" >
> <form method="post" onsubmit="return check()">
> <language = "javascript">
> BUILD()
> </script>
> <input type="submit" value="submit">
> <input type="reset" value="clear">
> </form>
> </body>
> </html>
>
> Thanks!
I'm guessing your code is trying to populate a table built on the
client-size (via "build()") with server-side data per "populateJob()".
Ain't gonna happen! Server-side code executes first. Try building the
entire table server-side; such as:
<% @language = "Javascript" %>
<%
// Build Array
.................................................. ................
var job = Request.Form("txt");
var mdb = "C:/Inetpub/wwwroot/ITI/fpdb/resume04.mdb";
var ado = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=" + mdb;
var sql = "select distinct Preference from Preferences"
var rst = Server.CreateObject("ADODB.Recordset");
rst.Open(sql,ado);
var n = 0;
var stateID = new Array();
var stateDesc = new Array();
while (!rst.EOF) {
stateID[n] = rst.Fields("Preference");
stateDesc[n] = rst.Fields("Preference");
n++;
rst.MoveNext();
}
rst.Close();
// Build Table
.................................................. ................
var num = 0;
var val;
var tbl = "<table border='0'>\n";
for (var i=0; i<n; i++) {
tbl += "<tr>\n";
for (var j=0; j<4; j++) {
var chk = "";
if (job.stateID[i] != -1) chk = " checked";
tbl += " <td>\n";
tbl += " <input type='radio' name='box' value='Box" + num + "' +
chk + ">\n";
tbl += " </td>\n";
num++;
}
val = stateDesc[i] + "," + stateID[i];
tbl += " <td>\n";
tbl += " <input type='text' name='txt" + num + "' value='" + val +
"'>\n";
tbl += " </td>\n";
tbl += "</tr>\n";
}
tbl += "</table>\n";
%>
<html>
<head>
<title>Resume</title>
<script language="javascript" type="text/javascript">
function check() {
// { check something }
return true;
}
// -->
</script>
</head>
<body>
<form method="post" name="RepForm" onsubmit="return check()">
<%=tbl%>
<input type="submit" value="submit">
<input type="reset" value="clear">
</form>
</body>
</html>
P.S. I'm not sure if my snippet
if (job.stateID[i] != -1)
is the same as yours
if (new String(strJob).search(stateID) != -1)
Note: the above is pseudo-code. You may have to tweak it to get it to work.
Watch for word-wrap.
McKirahan Guest
-
Jeremy #3
Re: populating text from database
Actually, here is a more concise version of the script I'm haing
trouble with...
<%@ language = "Javascript" %>
<%
var strJob = "";
var strconnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:/Inetpub/wwwroot/ITI/fpdb/resume04.mdb";
%>
<script language=Javascript>
function populateJob()
{
<%
var rs = Server.CreateObject("ADODB.Recordset");
var sql = "select distinct Preference from Preferences"
rs.Open(sql,strconnection);
var n=0;
while (!rs.EOF)
{
var pref = rs.Fields("Preference");
{
var tbl = "<table border='0'>\n";
{
tbl += "<tr>\n";
for (var j=0; j<4; j++)
{
tbl += " <td>\n";
tbl += " <input type='radio' name='box' value='Box"
+ n + "'>\n";
tbl += " </td>\n";
}
tbl += " <td>\n";
tbl += " <input type='text' name='txt" + n + "' value='"
+ pref + "'>\n";
tbl += " </td>\n";
tbl += "</tr>\n";
}
tbl += "</table>\n";
Response.Write("document.repForm.write('" + tbl + "')");
}
rs.MoveNext();
n++;
}
rs.Close();
%>
}
</script>
<html>
<head>
<title>Resume</title>
</head>
<BODY onload = "PopulateJob();" >
<form name="repForm" method="post" onsubmit="return check()">
<input type="submit" value="submit">
<input type="reset" value="clear">
</form>
</body>
</html>
Jeremy Guest



Reply With Quote

