Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help selecting a value from a list with multiple ids that are the same

 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a list in this basic format (2 items in the following example - be aware I had to put onClick outside of the <'li'> element, otherwise it was not displaying correctly):

As you can see onClick I call address_dropdown_select passing in the address_id, country and html of the item. I need a way to get the value of customer_name depending on which item is clicked on. I can use javascript or jQuery to accomplish this, but will listen to any other suggestions.
I can probably add in a 4th param that I pass which would be the customer_name value, but I would like to avoid this if I can. Can anyone give me some guidance on this?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not valid to have multiple elements with the same id and nothing will work as expected until you fix this.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the html spec for ids: http://www.w3.org/TR/html4/struct/global.html#h-7.5.2

HTML5 has same restriction, but has different naming requirements.

Eric
 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:It is not valid to have multiple elements with the same id and nothing will work as expected until you fix this.


Hmm well I must have mis stated something or be missing something, because this has been working like this for quite some time now. I am not sure what you mean when you say nothing will work as expected.
I will see what else I can figure out :/
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have invalid HTML there is no telling what will happen -- it will be non-deterministic.

Fix the page such that each id is unique -- anything else is irresponsible.
 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well unfortunately I do not have direct access to fix this myself, but I have passed it along. Thanks for the help. Unfortunately for now I still have to work with this as it is, so I am going to have to figure something else out.

So I know that the thing to do is fix this id issue, but putting that aside for now - could there be a way to work with this as it is and accomplish what I am trying to do?
I notice that I can use $(this).html(); to return the html of one list item at a time. Is it possible to extract the value I need from that by id? Something like $(this).html().($("#customer_name"))
I know that probably will not work, but just to give an idea of what I mean. I know I can probably get it using something like substr and/or instr, but that is not exactly desirable.
Someone also mentioned XPath as a possibility.

Also, the display of this list is incorrect in IE9 (but not IE8, FF or chrome) - the list is off to the right, but corrects itself once you select one of the items - could the id issue mentioned cause this kind of thing?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well it has the class set, so use that, also why are you using onclick in the html, add it dynamically!



Eric


 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:Well it has the class set, so use that, also why are you using onclick in the html, add it dynamically!



Eric




Ah that is one of the things I would change if I had control over it.
But your suggestion (slightly tweaked) works well:

Basically the only difference is I am using the div id rather than the class as the selector.

Perhaps you can help me understand why something similar I tried would not work:

Either way, thanks to all for the help and suggestions.



EDIT


I didn't realize it earlier, but I also needed to use the following to convert this to useable String
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic