Connecting Tech Pros Worldwide Forums | Help | Site Map

Creating a function utilising an array

Bundy
Guest
 
Posts: n/a
#1: Nov 20 '06
Hi

I am trying to create a function that adds to specific array, then
checks the array to determine whether to alert 'Yes' or 'No'.

Note this is a simplified version of the function I have created. This
function will be used with different arrays.


function change_value (check_value, array_name, array_number){

if (check_value == 'yes') {
array_name[array_number]='Y';
}
else{
delete array_name[array_number];
}

// check if there is a 'Y' anywhere in the array
if(array_name.length>0){
alert('Yes');
}
else{
alert('No');
}
return array_name;
}

Your help will be appreciated.

Regards

Bundy

Lee
Guest
 
Posts: n/a
#2: Nov 20 '06

re: Creating a function utilising an array


Bundy said:
Quote:
>
>Hi
>
>I am trying to create a function that adds to specific array, then
>checks the array to determine whether to alert 'Yes' or 'No'.
>
>Note this is a simplified version of the function I have created. This
>function will be used with different arrays.
>
>
>function change_value (check_value, array_name, array_number){
>
> if (check_value == 'yes') {
> array_name[array_number]='Y';
> }
> else{
> delete array_name[array_number];
> }
>
> // check if there is a 'Y' anywhere in the array
> if(array_name.length>0){
> alert('Yes');
> }
> else{
> alert('No');
> }
> return array_name;
>}
>
>Your help will be appreciated.
What sort of help are you expecting? Since you haven't told
us what this simplified version is supposed to do or what it
is that it isn't doing that you want it to do, it's sort of
hard to know how to help.


--

Dr J R Stockton
Guest
 
Posts: n/a
#3: Nov 21 '06

re: Creating a function utilising an array


In comp.lang.javascript message
<4561d874$0$32756$9a6e19ea@unlimited.newshosting.c om>, Mon, 20 Nov 2006
16:31:51, Bundy <bigbadbundyREMOVETHIS@vfemail.netwrote:

Untested :

function change_value (check_value, array_name, array_number){

if (check_value == 'yes') {
array_name[array_number]='Y';
}
else{
delete array_name[array_number];
}

// check if there is a 'Y' anywhere in the array
//- if(array_name.length>0){
//+
for (var J=0; J<array_name.length ; J++) if (array_name[J]=="Y") break
if (J != array_name.length) {
//+
alert('Yes');
}
else{
alert('No');
}
return array_name;
}


or alert (J != array_name.length ? "aye" : "nay")

It's a good idea to read the newsgroup and its old FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/ Old RC FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Bundy
Guest
 
Posts: n/a
#4: Nov 21 '06

re: Creating a function utilising an array


aye it works.

Also, thanks for directing me to the FAQ, it answered many questions.

Regards

Bundy
Closed Thread


Similar JavaScript / Ajax / DHTML bytes