473,769 Members | 7,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically dependant listBoxes

I am have used php to create a two sets of arrays of listboxes, each
of the listbox in the array have a unique ID. One of the list boxes
are dependant on the other one. I have written the code in javascript,
well changed existing code. I need to be able to select the element by
ID rather than name. The code was working before I changed things to
"getElementByID ". I am not very good at javascript so I am not sure if
I am on the right track, currently nothing is happening.

This is the Javascript code:
function swapName(form, i) {
var Type = 'lsType' + i;
var Name = 'lsName' + i;
Type = document.getEle mentByID(Type). options[document.getEle mentByID(Type). selectedIndex].value;

// this bit resets the name select list to nothing.
while (document.getEl ementByID(Name) .options.length > 1)
document.getEle mentByID(Name). options[0] = null;
// this bit populates the name select list with the required cities.
if (Type.length > 0) {
current_array=N ames[Type];

for (j=0;j<current_ array.length;j+ +) {
var optionName = new Option(current_ array[j], current_array[j],
false);
document.getEle mentByID(Name). options[document.getEle mentByID(Name). length]
= optionName;
}
}
}

This is the bit that calls it:
<select name="lsType[]" onChange="swapN ame(this.form,' .$i.')"
id="lsType'.$i. '">

Any suggestions would be welcome
Thanks in advance!
Jul 20 '05 #1
2 2562
"nadia" <ns***@student. cpit.ac.nz> wrote in message
news:9c******** *************** **@posting.goog le.com...
<snip>
This is the Javascript code:
function swapName(form, i) {
var Type = 'lsType' + i; <snip> This is the bit that calls it:
<select name="lsType[]" onChange="swapN ame(this.form,' .$i.')"
id="lsType'.$i. '">

<snip>

When you build the Type local variable to use as the ID you are not
including the two single quote characters that you have used in the ID
attribute string. Those single quotes are illegal characters in HTML
terms, as is the $ and the [ and ] in the name attribute so even if you
do include them in when building the Type local variable you should not
have any expectation of the result working on more than just some (if
common) HTML browsers.

From the HTML specification:-
<quote>
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods (".").
</quote>

Richard.
Jul 20 '05 #2
ns***@student.c pit.ac.nz (nadia) writes:
The code was working before I changed things to
"getElementByID ".
Then it is probably because it is with a lower case "d":
document.getEle mentById
^ This is the Javascript code:
function swapName(form, i) {
var Type = 'lsType' + i;
var Name = 'lsName' + i;
Type = document.getEle mentByID(Type). options[document.getEle mentByID(Type). selectedIndex].value;
I would split this into two lines:
var selElem = document.getEle mentById(Type);
var selValue = selElem.options[selElem.selecte dIndex].value;

(purely for style, I don't want to reuse variables more than necessary).
<select name="lsType[]" onChange="swapN ame(this.form,' .$i.')"
id="lsType'.$i. '">


I assume this is part of a PHP string declaration, and the the value
of $i is concatenated with the rest of the string. Be aware that not
everybody in this newsgroup knows PHP (I know only a little), and that
the PHP code used to generate the page really isn't interesting to us.
What is interesting is the HTML that is generated, since that is where
the bug is.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

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

Similar topics

1
3193
by: Will | last post by:
Hi, I have a problem trying to validate dynamically created html form elements using javascript. I have dynamically created a check box using ASP for each record in a recordset and have given each a unique ID using the primary key from a db table. e.g "chk" + "1" for record 1 and "chk" + "2" for record 2 etc. This means each box is called chk1 and chk2 respectively. This works fine and changes dependant on the recordset used and allows me...
1
3351
by: mlarson | last post by:
Hello, I'm working on a page that dynamically creates listboxes and the "options" that are added to the listbox. A user can then click on buttons to either add or delete the "options" from one listbox to the other. All of this works fine, but when the user changes from one page to the next, I'm trying to save all user input before it redirects to the next page. For some reason, I can't see what values have been selected in one of the...
4
1915
by: bill yeager | last post by:
I have several template columns inside of a datagrid. Inside of these template columns are databound listboxes: <asp:TemplateColumn HeaderText="Crew Chiefs"> <ItemTemplate> <asp:listbox AutoPostBack="False" BackColor="#ffffff" id="lstCrewChief" runat="server" Rows="1" DataSource="<%# DsCrewChief1 %>" Enabled="True"
0
1101
by: Terry D | last post by:
I'm having an issue with an ASP.NET page (VS.NET 2003, VB.NET, Oracle back end). The page uses the standard VS.NET grid to display the records from a particular table. The user can edit certain fields in the grid. There are 10 columns in the grid, 5 static fields (labels), 4 listboxes, and 1 edit box. 2 of the listboxes hold about 12 items each and the other 2 listboxes only contain 2 items. The problem is that on some lower end...
0
1586
by: Luis Esteban Valencia | last post by:
have a problem and I'm not sure how to handle/fix it. I have three listboxes on my page. The first listbox has a list of software products. When you select an item in the Products listbox, then the two other listboxes fill up with choices, one has related versions of that product, and the other has related Categories. Pretty typical stuff. Anyway, when I first designed the page, I used ASP.NET code to fill the values of the Version and...
0
1488
by: KBuser | last post by:
I'm building an internal site which will allow for extremely customizable queries to be run against our SQL Server (2000) DB. The page is done in ASP .net 2.0, with C# code behind. The initial page has a checkboxlist which is generated from a query which returns all the user tables in our database. This is checkboxlistTables. For each table selected in this list I want to dynamically generate a new checkboxlist in a (HTML) table on the...
1
2837
by: KBuser | last post by:
I'm building an internal site which will allow for extremely customizable queries to be run against our SQL Server (2000) DB. The page is done in ASP .net 2.0, with C# code behind. The initial page has a checkboxlist which is generated from a query which returns all the user tables in our database. This is checkboxlistTables. For each table selected in this list I want to dynamically generate a new checkboxlist in a (HTML) table on the...
7
1294
by: Csanád | last post by:
Hello, I have a form: http://www.steinrogan.com/SecureSite_v2_beta/new_item_single.html The idea is that every time the "Add a Dependant Item" button is clicked, the Item whose "Add a Dependant Item" button was clicked will have an additional field for another Dependant Item. Similarly, when the "Add Another Item" button is clicked, the form will have another Item with all the usual fields.
8
2565
by: Csanád | last post by:
Hi, Here's my form: http://www.steinrogan.com/SecureSite_v2_beta/addthis.php When I add two or more Dependant Items and remove one that's not the last that I added, I won't be able to remove any more Dependant Items. Say I deleted the first Dependant Item and try to remove the second Dependant Item - it will try to look for the link inactive.html that should never be accessed. I believe the problem is with reassigning the onclick...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10048
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.