[thelist] adding form fields based on field value

VOLKAN ÖZÇELİK volkan.ozcelik at gmail.com
Tue Mar 1 17:35:04 CST 2005


Here is a quick and dirty way to do this. It works though, and is
pretty cross-browser.

You can use a more elegant approach (i.e. appending nodes using DOM
methods instead of just appending innerHTML).

If you haven't looked at yet, see quirksmode.org. It is a good
starting place for learning JS, DOM etc. (it's good starting place for
learning JS anyway)

<html>
<head>
<script type="text/javascript">
	window.onload = function() {
		document.forms[0].myInput.onchange = function() {
			showWhateverNecessary();
		}
	}

	function showWhateverNecessary() {
		var obj = document.forms[0].myInput;
		var intVal = parseInt(obj.value);
		if(isNaN(intVal)) {intVal = 0;}

		var console = document.getElementById("FieldSetLayer");
		for(var i=0;i<=intVal;i++) {
			console.innerHTML += "<input type='text' name='DD_"+i+"' value='DD'
/> <input type='text' name='MM_"+i+"' value='MM' /> <input type='text'
name='YYYY_"+i+"'value='YYYY' /><br />";
		}
	}
</script>
</head>
<body>
	<form>
	input : <input type="text" id="myInput" name="myInput" value="" />
	</form>
	<div id="FieldSetLayer"><br /></div>
</body>
</html>


On Tue, 1 Mar 2005 16:32:31 -0600, Pringle, Ron <RPringle at aurora-il.org> wrote:
> Ok, got the form validation portion all sussed out now. Thanks everyone for
> their help!
> 
> My next problem.
> 
> Each event that gets entered into the form could have more than one date,
> start time and end time associated with it. The classic one-to-many
> relationship.
> 
> In my form I would like to create a 2 digit text field into which could be
> entered the number of dates for the event. Once a value is entered, I need
> to grab it and feed it to a loop that will then display the appropriate
> number of fieldsets (with each containing a field for date/time start/time
> end).
> 
> This has to happen dynamically on the form page without reloading the page.
> I assume I'll have to use javascript for this? Can anyone point me in the
> right direction?
> 
> Regards,
> Ron
> --
> 
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> 
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>


More information about the thelist mailing list