problem
hi
I am using the code below to allow the user to click a button and when pushed a new row appears in a table with a <SELECT> drop down box appearing.
Problem is that I think I am not coding it correctly, as it shows drop down twice.
Can someone help?
thanks
Craig.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
var Table2RowId = 0;
function addRow_table2()
{
Table2RowId++;
var tbody = document.getElementById('table2').getElementsByTagName('tbody')[0];
var row = document.createElement('TR');
var cell1 = document.createElement('TD');
var inp1 = document.createElement('SELECT');
inp1.setAttribute('name','selectvar'+Table2RowId);
//cell1.innerHTML = "<select name='service" + Table2RowId + "'><option value='1'>Microsoft</option><option value='2'>Macromedia</option>";
cell1.innerHTML= myDiv.innerHTML
row.appendChild(cell1);
tbody.appendChild(row);
}
</script>
<div id="myDiv">
<select name="firstSelect" >
<option>11111</option>
<option>22222</option>
<option>33333</option>
</select>
</div>
</head>
<body>
<table width="50%" border="1" id="table2">
<tr>
<td><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Software
Manufacturer</font></td>
</tr>
</table>
<input type="button" value="Insert Row" name="b2" onClick="addRow_table2();">
</body>
Somehow confusing... Which are your main aims, after all? Can you detail a little bit your project specifications?
Hi,
Basically, I want a dynamic drop down box to appear in each row when a button is clicked.. the user then selects an option for each row than clicks Submit.
hopw this helps.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function addRow(tabid){
var mydata=
{
'1':'Microsoft',
'2':'Micromedia',
'3':'Apple'
}
var root=document.getElementById(tabid).getElementsByTagName('tbody')[0]
var n=root.getElementsByTagName('tr').length;
var row=document.createElement('tr');
var cell=document.createElement('td');
var sel=document.createElement('select');
sel.name='service'+n;
var opt;
for(a in mydata){
opt=document.createElement('option');
opt.value=a;
opt.appendChild(document.createTextNode(mydata[a]));
sel.appendChild(opt)
}
cell.appendChild(sel);
row.appendChild(cell);
root.appendChild(row)
}
</script>
</head>
<body>
<form>
<table width="50%" border="1" id="table2">
<tr>
<td><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Software
Manufacturer</font></td>
</tr>
</table>
<input type="button" value="Insert Row" name="b2" onclick="addRow('table2');">
</form>
</body>
</html>
Originally Posted by
Kor
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function addRow(tabid){
var mydata=
{
'1':'Microsoft',
'2':'Micromedia',
'3':'Apple'
}
var root=document.getElementById(tabid).getElementsByTagName('tbody')[0]
var n=root.getElementsByTagName('tr').length;
var row=document.createElement('tr');
var cell=document.createElement('td');
var sel=document.createElement('select');
sel.name='service'+n;
var opt;
for(a in mydata){
opt=document.createElement('option');
opt.value=a;
opt.appendChild(document.createTextNode(mydata[a]));
sel.appendChild(opt)
}
cell.appendChild(sel);
row.appendChild(cell);
root.appendChild(row)
}
</script>
</head>
<body>
<form>
<table width="50%" border="1" id="table2">
<tr>
<td><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Software
Manufacturer</font></td>
</tr>
</table>
<input type="button" value="Insert Row" name="b2" onclick="addRow('table2');">
</form>
</body>
</html>
Hi,thanks but I have aleady done it this way.. the problem is that I need to fill the select box dynamicly from an ADO record set (using ASP)
then write the property/values pairs of the mydata object using ASP
Originally Posted by
Kor
then write the property/values pairs of the mydata object using ASP
Hi, client side javascript cannot access server side variables.. thats the problem.
Originally Posted by
cjonline
Hi, client side javascript cannot access server side variables.. thats the problem.
Yeap, but server side language can write javascript variables on a page, that is what i mean.
Hi, I dont know how to do that.. can you post an example?
anybody help me with this please?
I'll make a copy of the thread to the ASP forum
Hi,
Can anyone help me with this?
I require asp to write javascript variables on a page (see previous posts)
Kor,
I dont think you've read my problem correctly.. I know how to retrieve data from a databse and display it to the screen.. the problem is that when a users clicks the add row button it creates a new ROW in my table with a drop down box (this works, using javascript). I need the drop down to contain dynamic information from an asp recordset.. thats the problem.. I dont know how to pull the recordset from the drop down box (created in javascript)
thanks.
I don't know ASP (but as I know PHP, I guess there must be no basic differences). Presuming you have created an ASP object from DB which has properties, and properties have values, you may build a javascript array.
Code:
var myArr=[
'<% Response.Write objRS("objProperty1") %>',
'<% Response.Write objRS("objProperty2") %>',
'<% Response.Write objRS("objProperty3") %>'
]
Now you can use that array's elements in your javascript code (myArr[0], myArr[1], myArr[2]).
Last edited by Kor; 10-09-2007 at 06:04 AM .
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks