Question

I need to use jQuery to change the value of any input field (on form submit) to an escaped value.

If the user types an apostrophe, I need it to change to an escaped value before it is submitted and inserted into my database:

' ---> /'

How do I get jQuery to check all input fields and textareas for an apostrophe upon submitting, change the value, then continue with the submit function?

EDIT: I understand this is not a secure method of handling such a request, but I do not have access to the server side code. Also, as this is on an intranet, I'm not looking for the most secure solution, just one that uses JavaScript to handle it.

Comments so far have been limited to describing why this is a bad practice. Would anyone know how to actually handle this request using JavaScript (preferably jQuery)?

Was it helpful?

Solution

Setting aside the fact that this is easily circumventable, and just dealing with the specific requirement of escaping apostrophes from all text inputs on submit, here's one method:

That's a pretty link heavy set of steps, but it should give you what you need to start understanding jQuery based event handling and DOM traversal and manipulation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top