469,287 Members | 2,426 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,287 developers. It's quick & easy.

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 3091


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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Sofia | last post: by
15 posts views Thread by drdoubt | last post: by
4 posts views Thread by Phil | last post: by
2 posts views Thread by Michael R. Pierotti | last post: by
reply views Thread by U S Contractors Offering Service A Non-profit | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.