Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Prioritize form field

Reply
Thread Tools

Prioritize form field

 
 
Frowning Freezer
Guest
Posts: n/a
 
      08-28-2008
How can the function below be rewritten to prioritize form fields instead of
other objects with the same name?

For example I want getele("title") to retrieve the form field named "title"
instead of document.title - how do I get it to do that?

function getele(n, d){
//argument 'n' is the name of the object you want to get
//argument 'd' is the document object, it is not required
var p,i,x;
if (!d) {
d = document;
}
if ( (p = n.indexOf("?")) > 0 && parent.frames.length) {
d = parent.frames[n.substring(p+1)].document;
n = n.substring(0,p);
}
if ( !(x=d[n]) && d.all) {
x = d.all[n];
}
for (i=0; !x && i < d.forms.length; i++) {
x = d.forms[i][n];
}
for (i=0; !x && d.layers && i < d.layers.length; i++) {
x = getele(n, d.layers[i].document);
}
if (!x && d.getElementById) {
x = d.getElementById(n);
}
return x;
}


Regards,
Allan Jensen


 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      08-31-2008
Safalra (Stephen Morley) wrote:
> On Thu, 28 Aug 2008 16:41:35 +0200, Frowning Freezer wrote:
>> How can the function below be rewritten to prioritize form fields instead of
>> other objects with the same name?
>>
>> For example I want getele("title") to retrieve the form field named "title"
>> instead of document.title - how do I get it to do that?
>>
>> function getele(n, d){
>> //argument 'n' is the name of the object you want to get
>> //argument 'd' is the document object, it is not required
>> var p,i,x;
>> [...]
>> for (i=0; !x && i < d.forms.length; i++) {
>> x = d.forms[i][n];
>> }
>> [...]
>> if (!x && d.getElementById) {
>> x = d.getElementById(n);
>> }
>> return x;
>> }

>
>
> You can move the following if-block up in the function:


Then the priority of it as compared to now would be *lower*, because
execution does not return after the assignment. So the *last* assignment
wins. So it should be moved down instead, but ...

> for (i=0; !x && i < d.forms.length; i++) {
> x = d.forms[i][n];
> }
>
> This is, however, the wrong solution [...]


.... ACK, in double meaning.


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prioritize VPN traffic over http, ftp, etc. mchadwick@aoainc.com Cisco 6 09-11-2012 12:06 PM
Using QoS to prioritize traffic ESM Cisco 2 10-27-2005 02:33 AM
prioritize traffic on PIX? Brian Bergin Cisco 4 05-17-2005 07:31 PM
How to prioritize voice within multipoint Phillip Wendell VOIP 0 12-10-2003 06:44 PM
Coding style to prioritize certain inputs Willem Oosthuizen VHDL 5 09-04-2003 05:17 PM



Advertisments