Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > A nested dynamic checkbox inside my dynamic form.

Reply
Thread Tools

A nested dynamic checkbox inside my dynamic form.

 
 
pizzy
Guest
Posts: n/a
 
      04-05-2005
I am having a problem with the last results. I can't seem to be able to
get the input2A and input3A to appear. I don't seem to have a problem
with the show and hide after a number is entered and submitted. If
anyone can answer my problem I will be greatly appreciated with a
prize. I actually have submitted it more than once and I haven't had
anyone been able to answer it yet.


________
enter # of input0A |_______|

[submit] [reset]


------------------------------**-------------------------
NOTE:THE RESULTS BELOW IS AFTER 2 IS ENTERED INTO THE input ABOVE


________
input1A |_______| [] "check here to add input2A and input3A"
________
input1B |_______| [] "check here to add input2B and input3B"


[submit] [reset]


------------------------------**-------------------------
NOTE: THE RESULTS BELOW WHAT HAPPENS WHEN THE FIRST CHECKBOX ABOVE IS
CLICKED
________ ________ ________
input1A |_______| [] input2A |_______| input3A |_______|
________
input1B |_______| [] "check here to add input2B and input3B"


[submit] [reset]

 
Reply With Quote
 
 
 
 
kaeli
Guest
Posts: n/a
 
      04-06-2005
In article <. com>,
enlightened us with...
> I am having a problem with the last results.


Post testable code or a URL.

--
--
~kaeli~
Press any key...NO, NO, NO, NOT THAT ONE!!!!!!
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

 
Reply With Quote
 
 
 
 
pizzy
Guest
Posts: n/a
 
      04-07-2005
I don't have any that works.

 
Reply With Quote
 
Fred Oz
Guest
Posts: n/a
 
      04-07-2005
pizzy wrote:
> I don't have any that works.
>


Now you do. Put in any value you like, it will keep adding 'em.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Add inputs </title>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
</head>
<body>

<style type="text/css">
table { /* border-collapse: collapse; */ border: 1px solid blue;
padding: 1px 1 1 1;}
..tip {font-size: 90%; color: #666633;}
</style>
<script type="text/javascript">

// Create an array of the letters of the alphabet
var alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');

// Add first set of inputs and checkbox
function addInputsA(f,t) {
// Clean and validate input
var n = t.value.replace(/\s+/g,'');
if (/\D+/.test(n) || 1 > n || '' == n) {
alert('Please enter an integer greater than 0');
if (t.focus) t.focus();
return;
}

// Delete the body containing the first input
delBody(t);

// Setup variables
var bA = document.getElementById('bodyA');
var i=0, oTr, oTd, oChk, txt, let;

// Add the inputs and checkboxes
do {
oTr = document.createElement('tr');
let = numToAlpha(i);
txt = 'Input-1-' + let;
addToTr(oTr,document.createTextNode(txt));

oInp = document.createElement('input');
oInp.name = txt;
addToTr(oTr,oInp);

oChk = document.createElement('input');
oChk.type = 'checkbox'
oChk.name = 'Check-1-' + let;
oChk.onclick = function() {addInputsB(this)};
addToTr(oTr,oChk);

addToTr(oTr,document.createTextNode(chkTxt(let)));

bA.appendChild(oTr);

} while (++i < n)
}

// Add second set of inputs
function addInputsB(y){
var x = y, oInp, txt;
var nBit = x.name.split('-');
// Go up to parent td
while (!/td/i.test(x.nodeName)) {
x = x.parentNode;
}
// Go to next td
x = x.nextSibling;
// Remove its content
delKids(x);

// If checkbox checked, put inputs into it
if (y.checked) {
for (var j=2; j<4; j++) {
txt = 'Input-' + j + '-' + nBit[2];
x.appendChild(document.createTextNode(txt));
oInp = document.createElement('input');
oInp.name = txt;
x.appendChild(oInp);
}
// Otherwise, put some text into it
} else {
x.appendChild(document.createTextNode(chkTxt(nBit[2])));
}
}

// Returns a string with value of 'a' appended
function chkTxt(a){
return 'Click to add inputs 2 & 3 ' + a;
}

// Deletes a tbody given any element inside the tbody to delete
function delBody(t) {
while ( !/tbody/i.test(t.nodeName)) {t = t.parentNode;}
t.parentNode.removeChild(t);
}

// Removes all child nodes of given element
function delKids(n) {
while (n.firstChild) {n.removeChild(n.firstChild)}
}

// Given a tr, append b to new cell, append cell to tr
function addToTr(a,b){
var oTd = document.createElement('td');
oTd.appendChild(b);
a.appendChild(oTd);
}

function numToAlpha(n){
var t='';
while (n > 0) {
t = alpha[n%26] + t;
n = Math.floor(n/26-1);
}
return (0 > n)? t : alpha[n] + t;
}

</script>

<form action="">
<table border="1">
<tbody>
<tr>
<td colspan="2">Enter number of inputs:
<input type="text" size="5" name="numInputs">
<input type="button" value="Add inputs" onclick="
addInputsA(this.form,this.form.numInputs);
">
<br>
<span class="tip">(Integer greater than 1)</span>
</td>
</tr>
</tbody>
<tbody id="bodyA">
</tbody>
<tbody>
<tr>
<td colspan="4">
<input type="reset">
<input type="submit">
</td>
</tr>
</tbody>
</table>
</form>

<!-- test harness for the number-to-alpha-index thing -->
<input type="text" size="10" onblur="
var o = document.getElementById('xx');
var n = +this.value, t='', m;
while (n > 0) {
t = alpha[n%26] + t;
n = Math.floor(n/26-1);
}
(0 > n)? t=t : t = alpha[n] + t;
o.innerHTML = t;

">
<span id="xx"></span>

</body>
</html>
 
Reply With Quote
 
pizzy
Guest
Posts: n/a
 
      04-07-2005
Thanks man, check your email I sent a personal message.

 
Reply With Quote
 
pizzy
Guest
Posts: n/a
 
      04-12-2005
Fred,

Can you put the following into laymens terms?

while (!/td/i.test(x.nodeName)) {
x = x.parentNode;
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to have a nested dynamic checkbox inside my dynamic form. pizzy Javascript 0 03-23-2005 03:32 AM
Dynamic temp. datagrid col.gen. -Session access inside a class inside a UserCtrl Andy Eshtry ASP .Net Datagrid Control 0 03-01-2004 11:48 PM
Dynamic temp. datagrid col.gen. -Session access inside a class inside a UserCtrl Andy Eshtry ASP .Net Building Controls 0 03-01-2004 11:48 PM
Dynamic temp. datagrid col.gen. -Session access inside a class inside a UserCtrl Andy Eshtry ASP .Net 0 03-01-2004 11:48 PM
Dynamic temp. datagrid col.gen. -Session access inside a class inside a UserCtrl Andy Eshtry ASP .Net 0 03-01-2004 11:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57