Click to See Complete Forum and Search --> : Adding new form Elements on clientside


Markallen85
09-01-2003, 03:51 AM
I have a form where the user is submitting a number of usernames. This form is then posted to the server for processing.

I need to be able to write the page so that only one input box shows up to start, then as the user adds new entries, I need to write new lines in the table, preferrably with no maximum limit.

I can't use the simpler method of writing the from with lots of empty boxes, and then only processing those which aren't empty, as the form is being posted to a URL that I have no control over, and has undefined handling for empty boxes.


Is there a way using javascript that I can just add:

<input type='text' Id=CellX size=20>

to the middle of an existing page. I've tried the document.write command, but this only seems to work as the page is loading, otherwise it clears the page first.

If there isn't a way of doing it, does anyone have an alternate solution? One other option was to submit the form to and asp page every time they add a user, the asp would send back to form with one extra input, but this would be kinda slow if the user has to reload the page repeatedly.

thanks
-mark

lillu
09-01-2003, 04:20 AM
Hi,

Yes, it's possible, however for IE only because of the insertAdjacentHTML method.

<html>
<head>
<script language="javascript">
function addForm(frm)
{
div1.insertAdjacentHTML("beforeEnd","<input type='text' name='text[]'><br>");
}
</script>
</head>

<body>
<form action="Ticket.html">

<input type=text name=text1>

<input type=button name=button1 value="Click here to add textbox" onClick="addForm(this.form)">

<div id="div1"></div>

</form>

</body>
</html>

Markallen85
09-01-2003, 04:29 AM
thanks :)

that's exactly what I need, being IE only isn't a problem, this is an intranet only and all compnay PC's run IE.

-mark