[Javascript] Text Field Arrays
Jeff Walters
jeff at cybermill.com
Wed May 2 01:36:01 CDT 2001
> <form name='configurator'>
> <input type='text' name='files_description[0]' size='18' maxlength='30'
> onBlur='return nochanging(this, 0)'>";
> <input type='text' name='files_description[1]' size='18' maxlength='30'
> onBlur='return nochanging(this, 1)'>";
> <input type='text' name='files_description[2]' size='18' maxlength='30'
> onBlur='return nochanging(this, 2)'>";
> <input type='text' name='files_description[3]' size='18' maxlength='30'
> onBlur='return nochanging(this, 3)'>";
> <input type='text' name='files_description[4]' size='18' maxlength='30'
> onBlur='return nochanging(this, 4)'>";
> <input type='text' name='files_description[5]' size='18' maxlength='30'
> onBlur='return nochanging(this, 5)'>";
> </form>
>
> I want to populate the values of one of those text fields onBlur so the value
> is predetermined so I wrote this:
>
> <script language='JavaScript'>
> function nochanging(elem,elementNum){
>
> var changeto;
>
> switch(elementNum)
> {
> case '1': changeto="Home Top Left"; break
> case '2': changeto="Home Top Right"; break
> case '3': changeto="Property List Top Left"; break
> case '4': changeto="Property List Top Right"; break
> case '5': changeto="Sale Sheet Top Left"; break
> case '6': changeto="Sale Sheet Top Right"; break
> }
>
> window.document.configurator.files_description[elementNum].value=changeto;
> }
> </script>
Elements in a form are already in a array. As is just about everything else
in a page. Try changing the values like so:
window.document.configurator.elements[elementNum].value=changeto;
Hope this helps,
Jeff
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jeff Walters (314) 962-4024
Cybermill Communications
8616 Joseph Ave
St. Louis, MO 63144
Jeff at cybermill.com
http://www.cybermill.com/
More information about the Javascript
mailing list