HighDots Forums  

Setting focus on a form edit field with array name

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss Setting focus on a form edit field with array name in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
RolandD
 
Posts: n/a

Default Setting focus on a form edit field with array name - 09-04-2005 , 10:10 AM






Hello all,

As a beginner in Javascript I am trying to set focus to a form field
which name is an array.

The regular way to set focus I found: document.form.field.focus()

The problem is now that the field is not a string but an array. JS is a
bit confusing to me with its arrays, since you can print them out so easily.

Here is an excerpt from the source code (generated via PHP):
-----
<input type="hidden" name="varnames[]" value="pid" />
Enter Individual ID:</td>
<td class="optionbox"><input type="text" name="vars[pid]" id="pid"
value="I1" style="direction: ltr;" />
<input type="hidden" name="type[pid]" value="INDI" />&nbsp;<a
href="javascript: Find ID" onclick="iopenfind(document.setupreport.pid);
return false;">Find ID</a></td></tr>
<script language="JavaScript" type="text/javascript">
document.setupreport.vars['pid'].focus();
</script>
-----

This gives me the following message: Error: document.setupreport.vars
has no properties

My question is now: How do I set focus to the field vars[pid]?

Thanks,

RolandD

Reply With Quote
  #2  
Old   
Kimmo Laine
 
Posts: n/a

Default Re: Setting focus on a form edit field with array name - 09-04-2005 , 01:00 PM






"RolandD" <rdalmulderno (AT) spamhotmail (DOT) com> kirjoitti
viestissä:431b0e5c$0$24126$ba620dc5 (AT) text (DOT) nova.planet.nl...
Quote:
Hello all,

As a beginner in Javascript I am trying to set focus to a form field which
name is an array.

The regular way to set focus I found: document.form.field.focus()

The problem is now that the field is not a string but an array. JS is a
bit confusing to me with its arrays, since you can print them out so
easily.

Here is an excerpt from the source code (generated via PHP):
-----
input type="hidden" name="varnames[]" value="pid" /
Enter Individual ID:</td
td class="optionbox"><input type="text" name="vars[pid]" id="pid"
value="I1" style="direction: ltr;" /
input type="hidden" name="type[pid]" value="INDI" />&nbsp;<a
href="javascript: Find ID" onclick="iopenfind(document.setupreport.pid);
return false;">Find ID</a></td></tr
script language="JavaScript" type="text/javascript"
document.setupreport.vars['pid'].focus();
/script
-----

This gives me the following message: Error: document.setupreport.vars has
no properties

My question is now: How do I set focus to the field vars[pid]?
Use an id!

<input type="text" name="vars[pid]" id="vars_pid" value="INDI" />
in script:
document.getElementById("vars_pid").focus();

--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>
Kimmo Laine <eternal.erectionN0 (AT) 5P4Mgmail (DOT) com>




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.