homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Javascript while loop not getting vars

 3:01 pm on Apr 13, 2012 (gmt 0)

I am trying to do a javascript while loop to access certain form elements, but I cannot seem to get this right. it simply doesn't work. Can anyone look at it and point me in the right direction?

var i = 1;
while(i < '36'){

if(document.aSearch.cF[i].value != '') document.uSearch.Squery.value = "#"+document.aSearch.lF[i].value+"# "+document.aSearch.fF[i].value+" '"+document.aSearch.cF[i].value+"'";



 3:32 pm on Apr 13, 2012 (gmt 0)

while(i < '36'){

you're treating i as a string there. Try this:

while(i < 36){


 5:26 pm on Apr 13, 2012 (gmt 0)

Thanks Fontiman, can't believe I missed that one...

I still have problems accessing the field though. When trying to access the fields like this:

document.uSearch.Squery.value = document. aSearch.cF|i|.value;

I am getting: document.aSearch.cF|i| is undefined.
Tried all kind of variations, but to no avail. I know the fields exist.

The | represent square brackets, I can't post with square brackets here.

Any ideas?


 8:07 pm on Apr 13, 2012 (gmt 0)

Where is document.aSearch.cF defined? I assume aSearch is a form element, but what is cF?


 6:28 am on Apr 14, 2012 (gmt 0)

The fieldnames in the form (named aSearch) are named and id-ed cF1, cF2, cF3 etc.


 6:36 am on Apr 14, 2012 (gmt 0)

Just realised my approach was all wrong, Javascript is pretty new to me.

I am now using:

And that works. Thanks Fotiman for your support!


 9:09 pm on Apr 14, 2012 (gmt 0)

Glad you got it sorted. :-)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved