473,761 Members | 2,440 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Elements with the same name

Hi.

<div id="id1">
<select name="name">
//options
</select>
</div>

<div id="id2">
<select name="name">
//options
</select>
</div>

Is it ok to have two or more select lists with the same name? (Each in
different div)
Is is possible to check which value from which select was chosen?
For example using php $_POST
or there will be just one value remembered because all select list have the
same name?

Thanks.
Leszek
Feb 7 '06 #1
4 1657
Leszek wrote:
Hi.

<div id="id1">
<select name="name">
//options
</select>
</div>

<div id="id2">
<select name="name">
//options
</select>
</div>

Is it ok to have two or more select lists with the same name? (Each in
different div)
No.
The receiving scipt (the one mentioned in the action of the form) will have
trouble telling them appart.
Is is possible to check which value from which select was chosen?
Not if they have the same name!
Why not just name them differently?
For example using php $_POST
or there will be just one value remembered because all select list have
the same name?
indeed.

Thanks.
Leszek

regards,
Erwin Moller
Feb 7 '06 #2
Not sure what you're trying to achieve (javascript issues?), but if
it's of any help, you can do name[] and make it into an array.

e.g. <select name="name[]"></select>

Using name[] you can have multiple selects/inputs with the same form
name.

However, of course it's best if you use distinct names to tell them
apart.

Hope this helps.

Feb 7 '06 #3
Leszek wrote:
Hi.

<div id="id1">
<select name="name">
//options
</select>
</div>

<div id="id2">
<select name="name">
//options
</select>
</div>

Is it ok to have two or more select lists with the same name? (Each in
different div)
It's legal. If they're in two different forms, only the one that belongs
to the form being submitted will get sent back to the server anyway. If
they're in the same form, the question becomes: why are you doing this?

What will happen is that two name/value pairs will get sent to the server:

name={value of option selected from list 1}
name={value of option selected from list 2}

What the server will do with this is a different question. I saw someone
else refer to using "name[]". I've only glanced at PHP, but that sounds
familiar: it causes PHP to create an array out of the values, IIRC. In
ASP, though, you don't need the brackets: if more than one name/value
pair having the same name is received, ASP will treat it as an array.
Is is possible to check which value from which select was chosen?
For example using php $_POST
or there will be just one value remembered because all select list have the
same name?

Feb 7 '06 #4
Stanch wrote:
Not sure what you're trying to achieve (javascript issues?), but if
it's of any help, you can do name[] and make it into an array.

e.g. <select name="name[]"></select>

Using name[] you can have multiple selects/inputs with the same form
name.

Actually the brackets in the name is needed if the receiving script is PHP

<form_element name="some_name[]" ...

but not needed for Perl or JavaScript

<form_element name="some_name " ...
However, of course it's best if you use distinct names to tell them
apart.


Can be very usefully on a form that collects like data but the quantity
is unknown. Say for instance an order form {PHP example}

1st item
<input type="text" name="item[]">
<input type="text" name="price[]">
<input type="text" name="qty[]">
<input type="text" name="amount[]">

2nd item
<input type="text" name="item[]">
<input type="text" name="price[]">
<input type="text" name="qty[]">
<input type="text" name="amount[]">
....

nth item
<input type="text" name="item[]">
<input type="text" name="price[]">
<input type="text" name="qty[]">
<input type="text" name="amount[]">

count the elements in the array, iterate though them and build up an
order...

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Feb 7 '06 #5

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

Similar topics

0
4226
by: C. M. Sperberg-McQueen | last post by:
wooks (wookiz@hotmail.com) wrote: > <?xml version='1.0'?> > <userlogin xmlns="urn:faster:userlogin" > xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> > <login>mick</login> > <password>brown</password> > </userlogin> > Above is my schema instance.
4
6781
by: Doug Estep | last post by:
Below is a sample of my XML… <MetaData> <Table name="mytable"> <PrimaryKey name="pk"><Column name="mycolumn"/></PrimaryKey> </Table> </MetaData> <Sequencer> <Table name="mytable">
22
3337
by: Luke | last post by:
Elements with name attribute: form, input, textarea, a, frame, iframe, button, select, map, meta, applet, object, param, img (if you know more reply...) Methods of addresing html elements: <form name="myform"> <input name="myinput" /> </form> 1. var input = document.forms.myform.myinput;//from nn3+ 2. var input = document.forms.myinput;//from nn3+
2
3363
by: Novice | last post by:
Hi all, I have to decide on an XML structure going forward. The structure is going to house a large amount of data. In the past I've always just used the philosophy of "when in doubt use elements" - but I just read this article: http://msdn.microsoft.com/library/default.asp?URL=/library/en-us/dnexxml/html/xml02212000.asp And there is some indication that you will gain performance benefits from XML that uses attributes rather than...
2
4600
by: richardkreidl | last post by:
I want to be able to delete and search for elements in a XML file, I'm using the code below for adding elements which works great: Public Sub cmdAddElement_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddElement.Click Dim doc As New XmlDocument doc.Load("c:UMZ.xml") Dim root As XmlNode = doc.DocumentElement
1
1465
by: sam | last post by:
I have form elements which dynamically generated like this... <form name="formA" ...> <input type="select" name="text_1" ...> <input type="select" name="text_2" ...> <input type="select" name="text_3" ...> <input type="select" name="text_4" ...> </form> And I doing some validation like this.
1
1685
by: daldridge | last post by:
I have a unique-elements/sorting question (who doesn't?), but haven't yet been able to get appropriate template/select/for-each processing working. I don't fully grok the Muenchian technique yet (still an XSLT n00b), but I'm not sure that's the way to go anyway... What I'm trying to accomplish is generation of XML Schema output from a given XML input, with "xs:import" elements in the output with the "namespace" and "schemaLocation"...
2
1972
by: mavis | last post by:
Could you please help me with this xsd definition? I need to define a set of elements occur in any order with multiple occurrences, but the same kind of elements need to group together... Sth like this.... <xs:element name="A"> <xs:complexType> <xs:all>
3
2663
by: jonniethecodeprince | last post by:
Hi all, I have trouble getting an array of data stored in a separate javascript file i.e. a file called books.js into a table of data for a .xhtml file. There are 50 Records in this file. There are 5 colums of data I wish to display. I want to display these records in groups of 10. Based on the fact that the records I want are located in a separate file, how can I get these details to show on the form and manipulate the data to...
4
11236
by: Walton | last post by:
checkout: (3rd paragraph under 'Remarks' section) http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/name_2.asp from the page: "The NAME attribute cannot be set at run time on elements dynamically created with the createElement method. To create an element with a name attribute, include the attribute and value when using the createElement method." to work around this you have to code:
0
9522
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
9336
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
9948
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...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
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
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5215
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...
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.