Jump to content

Get jQuery to read arrayed ID's

Go to solution Solved by codesidian,

This is bad, and i highly recommend trying to find out why what you're currently doing isn't working. 

 

For now though try using an attribute selector or escaping the meta-characters:

alert($('[id="#AA[0][1][A]"]').val());
alert($("#AA\\[0\\]\\[1\\]\\[A\\]").val());

 

 

Delete this before posting. Please make sure to include the language that you're using in the title, and use the <> button for any code.

I have a modular table, its size depending on the array that makes it. Its ID would look something like "AA[0][1][A]"

 

Haven't found anything that I can pinpoint at but it seems like jQuery doesn't like arrayed ID's. My normal ID's work when jQuering like

alert($("#I001").val());

but the moment try to do it in the form of my array ID it's a dud. I've tried

alert($("#AA[0][1][A]").val());

As well as 

var IDValue = "AA[0][1][A]";
alert($("#" + IDValue).val());

And still nothing. Everything always comes back as "undefined."

 

Feels like an amateurish mistake but it's hooked me and I can't let go. I need to know why my jQuery isn't working, well the array ID at least, normal ID is fine.

MAIN: Ryzen 7 5800X3D - Kraken X62 Rev 2 - STRIX X470-I - 3600MHz 32GB Kingston Fury - 250GB 970 Evo boot - 2x 500GB 860 Evo - 1TB P3 - 4TB HDD - RX6800 - Antec HCG Platinum - Manta - Silent Wings Pro 4's enjoyer

SetupZowie XL2740 27.0" 240hz - Roccat Burt Pro OG Corsair K70 browns - PC38X - Mackie CR5X's Mackie CR8S-XBT

Current build on PCPartPicker

 

 

HTPC: Ryzen 7 2700X - BeQuiet! Shadow Rock 3 - STRIX X570-F - 3200MHz 32GB Corsair Dominator - 250GB Exceria boot - 500GB SN730 - 1TB Sandisk 3D - 4TB HDD - Limited Edition Vega 64 - Corsair RM750x 80+ Gold - North - Alphacool Apex Stealth Metal - BeQuiet! Light Wings

SetupHisense 55E7NQ - Hisense HS205G

HTPC on PCPartPicker

Link to comment
https://linustechtips.com/topic/1531940-get-jquery-to-read-arrayed-ids/
Share on other sites

Link to post
Share on other sites

6 hours ago, venomtail said:

I have a modular table, its size depending on the array that makes it. Its ID would look something like "AA[0][1][A]

Don't think HTML supports ids like that. AFAIK only characters a-z (upper/lower case), 0-9, underscores, hyphens and periods are supported. Ids should be unique, there should not be multiple items sharing the same name.

 

Named  form elements can supports arrays. I have used this in the past when bult processing multiple entries in a form.

 

Link to post
Share on other sites

10 minutes ago, Helly said:

It would help if you posted the html of the table itself. Perhaps theres a better way of creating it? Or getting whatever you want from it.

It's old. Literally just a tbody with text fields in each position, each having an ID generated from the array. Table number, Y pos and X pos.

 

I'll make a 21st century table hopefully in the next few months but for now I just need to get jQuery to cooperate.

MAIN: Ryzen 7 5800X3D - Kraken X62 Rev 2 - STRIX X470-I - 3600MHz 32GB Kingston Fury - 250GB 970 Evo boot - 2x 500GB 860 Evo - 1TB P3 - 4TB HDD - RX6800 - Antec HCG Platinum - Manta - Silent Wings Pro 4's enjoyer

SetupZowie XL2740 27.0" 240hz - Roccat Burt Pro OG Corsair K70 browns - PC38X - Mackie CR5X's Mackie CR8S-XBT

Current build on PCPartPicker

 

 

HTPC: Ryzen 7 2700X - BeQuiet! Shadow Rock 3 - STRIX X570-F - 3200MHz 32GB Corsair Dominator - 250GB Exceria boot - 500GB SN730 - 1TB Sandisk 3D - 4TB HDD - Limited Edition Vega 64 - Corsair RM750x 80+ Gold - North - Alphacool Apex Stealth Metal - BeQuiet! Light Wings

SetupHisense 55E7NQ - Hisense HS205G

HTPC on PCPartPicker

Link to post
Share on other sites

This is bad, and i highly recommend trying to find out why what you're currently doing isn't working. 

 

For now though try using an attribute selector or escaping the meta-characters:

alert($('[id="#AA[0][1][A]"]').val());
alert($("#AA\\[0\\]\\[1\\]\\[A\\]").val());

 

 

Link to post
Share on other sites

9 hours ago, codesidian said:

This is bad, and i highly recommend trying to find out why what you're currently doing isn't working. 

 

For now though try using an attribute selector or escaping the meta-characters:

alert($('[id="#AA[0][1][A]"]').val());
alert($("#AA\\[0\\]\\[1\\]\\[A\\]").val());

Spent a whole day yesterday looking up possible things I could use. Found escape special characters, tried to see if they could work, they did. Been up and running for a day now. 

MAIN: Ryzen 7 5800X3D - Kraken X62 Rev 2 - STRIX X470-I - 3600MHz 32GB Kingston Fury - 250GB 970 Evo boot - 2x 500GB 860 Evo - 1TB P3 - 4TB HDD - RX6800 - Antec HCG Platinum - Manta - Silent Wings Pro 4's enjoyer

SetupZowie XL2740 27.0" 240hz - Roccat Burt Pro OG Corsair K70 browns - PC38X - Mackie CR5X's Mackie CR8S-XBT

Current build on PCPartPicker

 

 

HTPC: Ryzen 7 2700X - BeQuiet! Shadow Rock 3 - STRIX X570-F - 3200MHz 32GB Corsair Dominator - 250GB Exceria boot - 500GB SN730 - 1TB Sandisk 3D - 4TB HDD - Limited Edition Vega 64 - Corsair RM750x 80+ Gold - North - Alphacool Apex Stealth Metal - BeQuiet! Light Wings

SetupHisense 55E7NQ - Hisense HS205G

HTPC on PCPartPicker

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×