473,385 Members | 1,453 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,385 software developers and data experts.

Script help

after Evertjan advice ;), I'm trying to cut down a complex task in many
easier ones.

Here is the code I'm trying to get to work:

function CheckGroup(X){
code = X.value;
alert(code); //this is OK !!!!

obj = document.getElementById('option[]');
alert('object length '+obj.length);
for ( index = 0; index < obj.length; index++ )
{
testcode = obj[index].value;
if(code == testcode)
alert('found...');
}
}

then I print several input type like this:
//generated by PHP...$newvalue are new values at every checkbox (concat in
PHP is ".")
<input type="checkbox" name="option[]" value=".$newvalue."
onclick="CheckGroup(this)");>

Every checkbox is part of the option array (look at the name). In the
CheckGroup function, I try to retrieve all $newvalue from the option[]
array. So I try to retrieve every single item in the option[] array, but
unfortunately, it doesn't work.
alert(obj.length); show and undefined value.

How can I retrieve such items values ???

Jul 23 '05 #1
7 1066
Bob Bedford wrote on 01 jul 2004 in comp.lang.javascript:
after Evertjan advice ;), I'm trying to cut down a complex task in
many easier ones.

Here is the code I'm trying to get to work:

function CheckGroup(X){
code = X.value;
alert(code); //this is OK !!!!

obj = document.getElementById('option[]');
alert('object length '+obj.length);
for ( index = 0; index < obj.length; index++ )
{
testcode = obj[index].value;
if(code == testcode)
alert('found...');
}
}

then I print several input type like this:
//generated by PHP...$newvalue are new values at every checkbox
(concat in PHP is ".")
<input type="checkbox" name="option[]" value=".$newvalue."
name="option[]"

1 This is not a HTML legal name.
2 this is not an ID, so getElementById should not find it [exept that som
browsers might have a bug.
3 id ="option[]" would aldso be illegal HTML.
4 you cannot make a javascript array like this

onclick="CheckGroup(this)");>
the ); is illegal

Every checkbox is part of the option array (look at the name). In the
CheckGroup function, I try to retrieve all $newvalue from the option[]
array. So I try to retrieve every single item in the option[] array,
but unfortunately, it doesn't work.
alert(obj.length); show and undefined value.

How can I retrieve such items values ???


I can only exchange PHP [because of my lack of knowledge of PHP]
by ASP(!!!) and you would get something like this:

<% for n= 1 to 25 %>
<input type="checkbox"
name="<%=option(n)%>"
id="<%=option(n)%>"
onclick="CheckGroup(this);"
value="<%=newvalue(n)%>">
<br>
<% next %>

And the clientside javascript can do:

function CheckGroup(X){
id = X.value;
alert(id); //this is OK !!!
}

and

obj = document.getElementById('<%=option(7)%>');
alert(obj.value)

==============

Bob, perhaps we will get somewhere.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #2
Evertjan. wrote:
<input type="checkbox" name="option[]" value=".$newvalue."
name="option[]"

1 This is not a HTML legal name.
Sure it is.
2 this is not an ID, so getElementById should not find it [exept that som
browsers might have a bug.
3 id ="option[]" would aldso be illegal HTML.


That is true, but as a name attribute, its perfectly legal and valid.

http://www.jibbering.com/faq/#FAQ4_25

<quote>
These characters are illegal within ID attributes in the standard
(x)HTML doctypes and javascript Identifiers
</quote>

Illegal in ID's, perfectly valid in NAMES.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #3


Bob Bedford wrote:

Here is the code I'm trying to get to work:

function CheckGroup(X){
code = X.value;
alert(code); //this is OK !!!!

obj = document.getElementById('option[]');
alert('object length '+obj.length);
for ( index = 0; index < obj.length; index++ )
{
testcode = obj[index].value;
if(code == testcode)
alert('found...');
}
}

then I print several input type like this:
//generated by PHP...$newvalue are new values at every checkbox (concat in
PHP is ".")
<input type="checkbox" name="option[]" value=".$newvalue."
onclick="CheckGroup(this)");>


Don't post your PHP here, we deal with HTML and JavaScript so use
view-source in your browser so that you can post HTML/JavaScript as the
browser sees it and not any server side scripting.

Now to your code, you pass the <input> element object to the CheckGroup
function which is fine but then you try
document.getElementById('option[]');
which is nonsense as you do not have any element with that id, what you
have are elements with that name. What you are looking for is
var inputs = X.form.elements[X.name];
This will give you a collection of all the controls in the form that
have the same name as the input you pass in as X.

As long as you are in the realms of form scripting the JavaScript 1.3
client-side documentation applies, I suggest you have a look at
http://devedge.netscape.com/library/...ipt/1.3/guide/
http://devedge.netscape.com/library/...1.3/reference/
which deals with that

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #4
"Evertjan." <ex**************@interxnl.net> a écrit dans le message de
news:Xn********************@194.109.133.29...
Bob Bedford wrote on 01 jul 2004 in comp.lang.javascript:
after Evertjan advice ;), I'm trying to cut down a complex task in
many easier ones.

Here is the code I'm trying to get to work:

function CheckGroup(X){
code = X.value;
alert(code); //this is OK !!!!

obj = document.getElementById('option[]');
alert('object length '+obj.length);
for ( index = 0; index < obj.length; index++ )
{
testcode = obj[index].value;
if(code == testcode)
alert('found...');
}
}

then I print several input type like this:
//generated by PHP...$newvalue are new values at every checkbox
(concat in PHP is ".")
<input type="checkbox" name="option[]" value=".$newvalue."


name="option[]"

1 This is not a HTML legal name.
2 this is not an ID, so getElementById should not find it [exept that som
browsers might have a bug.
3 id ="option[]" would aldso be illegal HTML.
4 you cannot make a javascript array like this

onclick="CheckGroup(this)");>


the ); is illegal

Every checkbox is part of the option array (look at the name). In the
CheckGroup function, I try to retrieve all $newvalue from the option[]
array. So I try to retrieve every single item in the option[] array,
but unfortunately, it doesn't work.
alert(obj.length); show and undefined value.

How can I retrieve such items values ???


I can only exchange PHP [because of my lack of knowledge of PHP]
by ASP(!!!) and you would get something like this:

<% for n= 1 to 25 %>
<input type="checkbox"
name="<%=option(n)%>"
id="<%=option(n)%>"
onclick="CheckGroup(this);"
value="<%=newvalue(n)%>">
<br>
<% next %>

And the clientside javascript can do:

function CheckGroup(X){
id = X.value;
alert(id); //this is OK !!!
}

and

obj = document.getElementById('<%=option(7)%>');
alert(obj.value)

==============

Bob, perhaps we will get somewhere.


Finally, with your help, I got it to work:
javascript:
function CheckGroup(X){
code = X.value;
alert(code);
obj = document.SubmitForm.option;
for ( index = 0; index < obj.length; index++ ){
alert('object values '+obj[index].value);
}
}

HMTL code:
....
<input type="checkbox" name="option" value="1422862"
onclick="CheckGroup(this)">
<input type="checkbox" name="option" value="1422863"
onclick="CheckGroup(this)">
....

Thanks for your help !!!

Now I will try to store a list of exclusion with this object. If somebody
know how to do so, please let me know.

Regards

Jul 23 '05 #5
Hi Evertjan,

Finally, I've been able to do what I wanted in the original post.

Thanks for your help !

(if you are interested, let me know....)

Best regards.

BoB

Jul 23 '05 #6
Randy Webb wrote:
Evertjan. wrote:
2 this is not an ID, so getElementById should not find it [exept
that som browsers might have a bug.
3 id ="option[]" would aldso be illegal HTML.
That is true, but as a name attribute, its perfectly legal and valid.

http://www.jibbering.com/faq/#FAQ4_25

<quote>
These characters are illegal within ID attributes in the standard
(x)HTML doctypes and javascript Identifiers
</quote>


I think this FAQ entry has created enough
misunderstandings to be rewritten.
Illegal in ID's, perfectly valid in NAMES.


Not *all* NAMEs because the "name" attributes you
are referring to are of type CDATA:

<http://www.w3.org/TR/html4/types.html#h-6.2>
<http://www.w3.org/TR/html4/index/attributes.html>
PointedEars
Jul 23 '05 #7
Thomas 'PointedEars' Lahn wrote:
Randy Webb wrote:
Evertjan. wrote:
2 this is not an ID, so getElementById should not find it [exept
that som browsers might have a bug.
3 id ="option[]" would aldso be illegal HTML.


That is true, but as a name attribute, its perfectly legal and valid.

http://www.jibbering.com/faq/#FAQ4_25

<quote>
These characters are illegal within ID attributes in the standard
(x)HTML doctypes and javascript Identifiers
</quote>

I think this FAQ entry has created enough
misunderstandings to be rewritten.


But it is factually correct as written, and the current wording was
chosen for a very explicit reason.


--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #8

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

Similar topics

3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
4
by: hupjack | last post by:
I finally joined the millions of cell phone users out there. I'm the 2nd phone on what is now a family share plan. (Our two cell phones use minutes from a central 400 minute peak time pool.)...
14
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
8
by: Johnny Knoxville | last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works fine if you add the site to favourites the normal way, but I have some JavaScript code on a couple of pages with a link,...
4
by: Derek | last post by:
I have the following script in a page and it gets an error in IE 6. Says something about an invalid argument but the line number doesn't help since I can't see the javascript code when viewing...
0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
9
by: Harry Smith | last post by:
While reading the documentation on IsStartupScriptRegistered, there is a reference to "client startup script" as "Determines if the client startup script is registered with the Page object." What...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
3
by: David | last post by:
On Sun, May 4, 2008 at 4:43 AM, lev <levlozhkin@gmail.comwrote: Hi, I started tidying up the script a bit, but there are some parts I don't understand or look buggy. So I'm forwarding you the...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.