473,385 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Need help with DOM

I have a script which adds a row. I am using the DOM model to do this.
I have an image link which is to be inserted next to a input field in
each row i add , how do i do this?

I think i have to change the "TD" elemement somehow , also my code
has to work in netscape. Has anybody got a solution to this :

<head>
<script type="text/javascript">
function addRow(id){

var index = document.form1.hidden.value;
var tbody = document.getElementById(id).getElementsByTagName(" TBODY")[0];
var row = document.createElement("TR");
row.setAttribute("id","row" + index);
//Clone this node
var targetNode = document.getElementById('SELECT')
input1 = targetNode.cloneNode(true)
input1.setAttribute("name","select" +index)

input2 = document.createElement("input");
input2.setAttribute("name","a" +index)
input2.setAttribute("value","")
input2.setAttribute("type","text")
input2.setAttribute("readOnly","false")
input2.setAttribute("size","32")

input3 = document.createElement("input");
input3.setAttribute("name","b" +index)
input3.setAttribute("value","")
input3.setAttribute("type","text")
input3.setAttribute("readOnly","false")
input3.setAttribute("size","8")

input4 = document.createElement("input");
input4.setAttribute("name","c" +index)
input4.setAttribute("value","")
input4.setAttribute("type","text")
input4.setAttribute("readOnly","false")
input4.setAttribute("size","5")

input5 = document.createElement("input");
input5.setAttribute("name","d" +index)
input5.setAttribute("value","")
input5.setAttribute("type","text")
input5.setAttribute("size","8")

var td1 = document.createElement("TD")
td1.appendChild(input1)

var td2 = document.createElement("TD")
td2.appendChild (input2)

var td3 = document.createElement("TD")
td3.appendChild (input3)

var td4 = document.createElement("TD")
td4.appendChild (input4)

var td5 = document.createElement("TD")
td5.appendChild (input5)

row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
row.appendChild(td4);
row.appendChild(td5);
tbody.appendChild(row);

//increase index of hidden field
index++
document.form1.hidden.value=index
}
</script>
</head>

<body>
<form name="form1">
<input type="hidden" value="0" name="hidden">
<table id="myTable" cellspacing="0" border="1">
<tr>
<td>&nbsp;<select size="1" name="havnkode" id="select">
<option value="02">Drop down</option>
<option value="00">Test1</option>
<option value="28">Test2</option>
<option value="06">Test3</option>
</td>
<td>row1_column1</td><td>row1_column1</td><td>
</tr>
</table>
<input type="button" value="new row"
onClick="javascript:addRow('myTable')">
</form>
</body>
</html>
Jul 20 '05 #1
1 3198


spaminator wrote:
I have a script which adds a row. I am using the DOM model to do this.
I have an image link which is to be inserted next to a input field in
each row i add , how do i do this?

I think i have to change the "TD" elemement somehow , also my code
has to work in netscape. Has anybody got a solution to this :


//create the link
var link = document.createElement('a');
//set href
link.href = 'whatever.html';
// create img element
var img = document.createElement('img');
img.src = 'whatever.gif';
img.alt = 'whatever';
//append img to link
link.appendChild(img);
//append link to table cell
cell.appendChild(link);

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its...
7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
15
by: drdoubt | last post by:
using namespace std In my C++ program, even after applying , I need to use the std namespace with the scope resolution operator, like, std::cout, std::vector. This I found a little bit...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
3
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
4
by: Phil | last post by:
k, here is my issue.. I have BLOB data in SQL that needs to be grabbed and made into a TIF file and placed on the client (could be in temp internet dir). The reason we need it in TIF format is...
8
by: Sai Kit Tong | last post by:
In the article, the description for "Modiy DLL That Contains Consumers That Use Managed Code and DLL Exports or Managed Entry Points" suggests the creation of the class ManagedWrapper. If I...
2
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.