0

I am trying to implement and undo feature in my webpage. It is a table full of editable texboxes so coming up with an id was hard. I decide to make an id name based of the table inforamtion. Here is an id for example:

 HW3=:25626=:10000

HW3 is the header, 25626 is the id column for the row and 10000 references this table. For the undo feature i get the id by using

 $(this).attr('id);

and this funciton is called based on the event focus or click that is why 'this' works. I take the current value and add it to the end like

 $(this).attr('id)+":="+old_value;

This is done becuase the id name is seperated by "=:" so i can do two splits to get this data back in parts. Might not be best I understand.

The problem i am having is when I try to pull out the id and put it back as an element I get the error:

 Uncaught Error: Syntax error, unrecognized expression: #HW3=:25626=:10000 

I am trying to do:

  var s = "#"+temp[0];
  var element = $(s);

temp[0] is = to HW3=:25626=:10000. It is the second line throwing this error.

IMPORTANT!!! The table that has the id that I am using is not created in the begining. JQuery calls a method that builds it after page loads. This method can not be access until after the table is created. I understand that you can not bind events to elements until after they load but I'm not sure if the is that same case since i will never try to undo on a textbox that is not present. After all it had to be present to be inserted into the Undo object already.

Any help is appreciated.

1 Answer 1

1

Your ID isn't going to work in a selector. You have to do something like this instead:

$(document.getElementById(temp[0]))
Sign up to request clarification or add additional context in comments.

4 Comments

How do you come up with that? if document.getElementById(temp[0]) will work then $("#"+temp[0]) should too, no?
@mplungjan: Not if the attribute contains characters that will break the selector. foo.bar is a valid id, but it'll make the selector work improperly.
what characters are invalid for a selector because this does not work. But i also found out that even typing in the id by hand does not work so i think im using invalid characters or something.
ok i found a list of valid characters and my = was not on it. So i changed those to -. Still not working. I did find that on my textbox when i change the value it does not change the value of the code. Still not getting this to work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.