Forum Moderators: open

Message Too Old, No Replies

Fill Table w Array

         

kmbarz

5:39 pm on Aug 10, 2004 (gmt 0)

10+ Year Member



I'm sure this is pretty basic, but then again Javascript isn't really my language.

I have a series of forms that I will be submitting to a database using Coldfusion. However, one section of my form will need to accept multiple lines of data (e.g. list all the medications and doses that you are on.)

As I have a trigger on the database that will fire on insert, I'd like to submit everything in one package. So, I'd like to be able to have the user fill out this section of the form and hit something like "Add Medication". I'm sure I'll store this in an array of some sort. But what I'd also like to do is have this record added to a table so the user can see each line as the add it. After all that, the form could be submitted in total via CF.

Any help out there to get me started?
Thanks

RonPK

6:21 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello kmbarz,

It's not that difficult - unless you insist on using a table. Adding elements to a table is rather messed up in IE.

Example without tables:

<script type="text/javascript"> 
function addmed() {
var mr = document.getElementById("myrows");
var t = mr.getElementsByTagName('div').length + 1;
mr.innerHTML += '<div>medication ' + t + ': <input name="med' + t + '" type="text"></div>';
}
</script>

<form> 
<div id="myrows">
<div>medication 1: <input name="med1" type="text"></div>
<div>medication 2: <input name="med2" type="text"></div>
</div>
<input type="button" value="add row" onclick="addmed()"> <input type="submit">
</form>

This won't work in Netscape 4, but who cares ;)
No problems in IE5+, recent Mozillas and Operas.