I have a drop down that has numbers, 1-4. I want the number value chosen to dynamically display the same number of text boxes.
For example - if the customer chooses 3 from the drop-down, I want three small text boxes to appear.
I can only find a javascript to dynamically load another drop-down with new values - how can I do this? Can you at least point me to a script or give me an example?
Any idea why this works fine on Mozilla/Netscape but not IE? It moves everything on the page as if it inserts a new form field, but the field is not visible in IE.
I tried using the code at that forumns page, but that too will not work in IE 6. It works just fine when you enter a value and hit enter in Firefox .9.3! I need something that works in both - but preferrably in IE!
I tried using the code at that forumns page, but that too will not work in IE 6. It works just fine when you enter a value and hit enter in Firefox .9.3! I need something that works in both - but preferrably in IE!
Uh....
I wrote and tested that code with IE6...
If it is not working for you, you are doing something wrong....
Can't possibly say what tho, since you have failed to post any code....
<script type="text/javascript">
<!--//
function addInputs(theInput){
var table = document.createElement('table');
table.id = 'hMembers';
var hMembers = document.getElementById('hMembers');
if(hMembers)theInput.parentNode.removeChild(hMembers);
if(theInput.value.match(/^d+$/)){
var tbody = document.createElement('tbody');
for(var i=0; i<theInput.value; i++){
var row = document.createElement('tr');
var cell = document.createElement('td');
var num = document.createTextNode((i+1)+')');
cell.appendChild(num);
row.appendChild(cell);
tbody.appendChild(row);
var cell = document.createElement('td');
var name = document.createTextNode('name:');
var input = document.createElement('input');
input.size = 20;
input.name = 'name'+(i+1);
cell.appendChild(name);
cell.appendChild(input);
row.appendChild(cell);
tbody.appendChild(row);
var cell = document.createElement('td');
var age = document.createTextNode('age:');
var input = document.createElement('input');
input.size = 1;
input.name = 'age'+(i+1);
cell.appendChild(age);
cell.appendChild(input);
row.appendChild(cell);
tbody.appendChild(row);
var cell = document.createElement('td');
var sex = document.createTextNode('sex:');
var input = document.createElement('input');
input.size = 2;
input.name = 'sex'+(i+1);
cell.appendChild(sex);
cell.appendChild(input);
row.appendChild(cell);
tbody.appendChild(row);
} table.appendChild(tbody);
theInput.parentNode.insertBefore(table,theInput.nextSibling);
}
else{ alert('Please enter only numbers in this field!');
theInput.value = '';
theInput.focus();
}
}
//-->
</script>
</head>
<body>
<form method="get" action="">
How many in the household: <input type="text" onchange="addInputs(this)">
</form>
This example uses an onchange event handler....
It is not enough to just type a number in... You must place focus somewhere else (such as clicking on the body or another form element) for the change to register.... Try changing that to onkeyup or something if you are not comfortable with the onchange event.....