1

I am reading rows from a mySQL table and returning them to jQuery to display (using HTML, bootstrap) for the user to enter a value against. When the value is updated by the user the action is capture by jQuery and the value is returned to be updated in the table (so I need the row's key in order to update the correct row).

So the user can not change the key, and have a different (wrong) row updated in the table, I am encrypting the row keys before sending them to the jQuery. I use the row's key as the id for each HTML line so each has a unique id and I know which has been update.

//Loop for each encoded_task_detail_ID
String summer = "ta" + encoded_task_detail_ID;
<textarea class='summernote col-lg-12 col-md-12 col-sm-12 col-xs-12' id="+ summer +" name='ymSpecificLine' rows='1'>
//end loop

Some rows are name='ymSpecificLine' and some are not. So in the jQuery I check:

var taKey = "#ta" + val_awardDetailID;

var val_ymSpecific = "N";
var val_ymSpecificLine = "";
alert("1");
if ($(taKey).attr('name') === "ymSpecificLine"){ //I have tried == here as well
    alert("2"); //Not displayed when error occurs
    val_ymSpecific = "Y";
    val_ymSpecificLine = $(taKey).val();
};

If the key (val_awardDetailID - same as encoded_task_detail_ID) is "Nzly" then this works. However, when the key is "MjM5MQ==" then there is a console error:

Uncaught Error: Syntax error, unrecognized expression: #taMjM5MQ==

I thought it may have something to do with it ending in "==" so I added an "A" to give "#taMjM5MQ==A". However the same error was returned.

2 Answers 2

2

use \\=\\= instead of ==, which escaped character =. Like: #taMjM5MQ\\=\\=A

And to replace that by code: taKey = taKey.split('=').join('\\=')
While this is not very effeciency there're many better 'replaceAll' implementations on the internet.

(Sorry for not being online for 2 days)

Sign up to request clarification or add additional context in comments.

Comments

1

jQuery selectors work similar to CSS selectors. #taMjM5MQ== is not a valid selector.

example: https://jsfiddle.net/reddysridhar53/hzycv82d/2/

6 Comments

Thank you. Is there a solution for this as I have this throughout my application and so is going to be a lot of work to correct.
Your keys are base 64 encoded I guess so you can decode using atob() and use var summer = "ta" + atob(encoded_task_detail_ID)
use \\=\\= instead of ==, which escaped character =. Like: #taMjM5MQ\\=\\=A
@MeowCat2012 - Each val_awardDetailID is different. How do I check the val_awardDetailID before using it and add the escape characters please?
sridhar reddy - this works; however, the changes to the system are far more extensive than if I can escape the characters. So the solution from @MeowCat2012 is my preferred if I can work out how to apply it.
|

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.