473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

better ways?

I have a menu of radio buttons with the name myform (thank you to Evertjan.
for your help with my other problem, I have no idea where the error was but
I worked through it from your advice) pretty much one of them HAS to be
selected (it would be hard to avoid it) and my loop cycles through until if
finds the checked button... as I have no way to tell how many items there
will be in the array of menu items I cant put a static number in the loop,
at the moment I have this....
for(i=0;document.menuform.myform[i] != undefined;i++)

as when you reach say document.menuform.myform[10] and there is no 10th it
will return "undefined", but this doesnt seem to be the best of ways to do
it? Is there any exceptions to this way? Any better ways? I tried while
(document.menuform.myform) thinking that reaching an undefined item would be
'false' but as you can guess i caused an infinite loop :(

So basically is there any better/easier ways to write this loop, and are
there any exceptions to this loop?
Thanks
Jul 20 '05 #1
4 1692

"Draken" <lo***************@hotmail.com> schrieb im Newsbeitrag
news:3f**************@echo-01.iinet.net.au...
I have a menu of radio buttons with the name myform (thank you to Evertjan. for your help with my other problem, I have no idea where the error was but I worked through it from your advice) pretty much one of them HAS to be
selected (it would be hard to avoid it) and my loop cycles through until if finds the checked button... as I have no way to tell how many items there
will be in the array of menu items I cant put a static number in the loop,
at the moment I have this....
for(i=0;document.menuform.myform[i] != undefined;i++)

as when you reach say document.menuform.myform[10] and there is no 10th it
will return "undefined", but this doesnt seem to be the best of ways to do
it? Is there any exceptions to this way? Any better ways? I tried while
(document.menuform.myform) thinking that reaching an undefined item would be 'false' but as you can guess i caused an infinite loop :(

So basically is there any better/easier ways to write this loop, and are
there any exceptions to this loop?
Thanks


for(i=0; i<document.menuform.myform.length; i++)

--
Markus
Jul 20 '05 #2

"Richard Cornford" <Ri*****@litotes.demon.co.uk> schreef in bericht
news:be*******************@news.demon.co.uk...
"Fred Serry" <fr***************@planet.nl> wrote in message
news:be**********@ID-108377.news.dfncis.de...
<snip>

Did you get that one backwards?
for(i=0;i<document.menuform.myform.elements.length ;i++)


for(i=0;i<document.menuform.elements.myform.length ;i++)

("myform" seems a misleading name to give to a set of radio buttons)

Richard.


Holidays starts tomorrow. Seems I need it :)
Jul 20 '05 #3
> ("myform" seems a misleading name to give to a set of radio buttons)
Richard.


Not sure if that is backwards, I didnt use it as the elements section isnt
needed. I called it myform simply because I had help in a different thread
called "help with onClick" or something like that and I copied and pasted
the code of a working example and didnt change anything, of course I could
change it, but I dont need to, its for a personal website and im the only
person who needs to understand it. The form used to be called menu... which
is a better name for the radio buttons which make up a menu, but I didnt use
that again incase that was some sort of reserved word that was causing an
error.

my only question is the operator... shouldn't it be i<= .. rather than just
< ?? cause if I have 10 array items doesnt the < operator stop at 9?

Jul 20 '05 #4
if i starts at 0 you have 10 values that are < 10, that's the trick...

--
Markus

my only question is the operator... shouldn't it be i<= .. rather than just < ?? cause if I have 10 array items doesnt the < operator stop at 9?

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Dan | last post by:
I have seen differing ways to pass values to a class: $db=new mysqlclass('localhost','user','passwd','database'); ..... OR $db=new mysqlclass() $db->host='localhost'; $db->user='user';...
4
by: Slant | last post by:
I have been using MySQL in conjunction with PHP for many years now... I have been using the exact same method for not only connecting to a database and performing the queries but also displaying...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
4
by: Nobody | last post by:
Lets say I have a class that is only available if a specific DLL (a.dll) is present. I can't link to that DLL through lib files or my app will fail on any machine that doesn't have a.dll. So I...
14
by: J.S. | last post by:
In a Windows Form application, which is the better method to concatenate large blocks of code? 1. Reading the text from text files. 2. Adding the text to the VB file itself? Thanks! J.S. ...
2
by: serge | last post by:
/* Subject: How best to use BETWEEN Begin and End Dates to find out if an employee was/is member of any group for a certain date range? You can copy/paste this whole post in SQL Query Analyzer...
22
by: JoeC | last post by:
I am working on another game project and it is comming along. It is an improvment over a previous version I wrote. I am trying to write better programs and often wonder how to get better at...
20
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
5
by: Nitesh | last post by:
Objects of type X are basic building blocks of my application and there are a few functions which return XHandle (typedef X** XHandle). The task at hand needs to use a couple of these functions and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.