- FrozenShellfish
- Aug 30, 2004
-
|
I'm making a nice website for a mobile library project in the Peruvian Andes, I tried to use javascript to make the forms easier to fill out and then I realised I don't have a clue what I am doing
This does what I want in firefox (adds/removes another row from the table) but it doesn't work at all in IE. Can someone fix it for me? Cheers.
http://new.bibliotecaurubamba.com/iesucks.htm
code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<script type="text/javascript">
// Last updated 2006-02-21
function addRowToTable()
{
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
// left cell
var cellLeft = row.insertCell(0);
var al = document.createElement('input');
al.type = 'text';
al.name = 'bookid' + iteration;
al.id = 'bookid' + iteration;
al.class = 'field';
al.tabindex='1';
al.maxlength='4';
al.size='5';
cellLeft.appendChild(al);
// right cell
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.type = 'text';
el.name = 'firstname' + iteration;
el.id = 'firstname' + iteration;
el.class = 'field';
el.tabindex='1';
el.maxlength='20';
el.size='21';
cellRight.appendChild(el);
// select cell
var cellRightSel = row.insertCell(2);
var ol = document.createElement('input');
ol.type = 'text';
ol.name = 'lastname' + iteration;
ol.id = 'lastname' + iteration;
ol.class = 'field';
ol.tabindex='1';
ol.maxlength='30';
ol.size='31';
cellRightSel.appendChild(ol);
}
function removeRowFromTable()
{
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}
function openInNewWindow(frm)
{
// open a blank window
var aWindow = window.open('', 'TableAddRowNewWindow',
'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');
// set the target to the blank window
frm.target = 'TableAddRowNewWindow';
// submit
frm.submit();
}
function validateRow(frm)
{
var chkb = document.getElementById('chkValidate');
if (chkb.checked) {
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length - 1;
var i;
for (i=1; i<=lastRow; i++) {
var aRow = document.getElementById('txtRow' + i);
if (aRow.value.length <= 0) {
alert('Row ' + i + ' is empty');
return;
}
}
}
openInNewWindow(frm);
}
</script>
</head>
<body>
<form action="./iesucks.htm" method="post">
<table border="1" id="tblSample">
<tr>
<th class=\"top\" scope=\"col\">BookID</th>
<th class=\"top\" scope=\"col\">First Name</th>
<th class=\"top\" scope=\"col\">Last Name</th>
</tr>
<tr>
<td><input type="text" name="bookid1" id="bookid1" size="5" maxlength="4" class="field" tabindex="1" /></td>
<td><input type="text" name="firstname1" id="firstname1" size="21" maxlength="20" class="field" tabindex="1" /></td>
<td><input type="text" name="lastname1" id="lastname1" size="31" maxlength="30" class="field" tabindex="1" /></td>
</tr>
</table>
<input type="hidden" name="done" value="1" />
<p>
<input type="button" value="One more" onclick="addRowToTable();" />
<input type="button" value="One less" onclick="removeRowFromTable();" />
<input type="submit" name="submit" id="submit_1" class="button" value="Submit" tabindex="6" />
</form>
</body>
</html>
edit: fixed it very soon after I posted this: it didn't like the line "al.class='field'" for some reason
FrozenShellfish fucked around with this message at 07:34 on Jun 8, 2009
|
#
¿
Jun 7, 2009 20:58
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
May 6, 2024 09:24
|
|