Abhradip Abhradip - 3 months ago 5x
jQuery Question

unable to parse string in getElementById

I am using jquery in my application and I am using ruby on rails. Now I want to get the data typed in a search box immediately during typing.Everything is working fine but the problem is that it can not catch the special characters like

etc. Its working fine for all other numericals and alphabets. I am using the getElementById technique to get data from textbox.

Please tell me any solution to get rid of this problem

My jquery code part is:

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<link rel="stylesheet" href="/resources/demos/style.css">

var box = document.getElementById("tags");
document.getElementById("abc").innerHTML = box.value;
$.getScript('/employees/new?pt=' + box.value)

Actually I want to send this captured data from textbox to my rails controller.My controller name is employees and action is new


You need to encode the special character in the parameter value using encodeURIComponent()

The encodeURIComponent() method encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).

$.getScript('/employees/new?pt=' + encodeURIComponent(box.value));