0

I have a problem with slash in javaScript n Ajax

I am displaying value dynamically in a span like below:

String num = "37-C110PDD/L";

<span id="p21stk_<%=NUM%>"></span>

in Script:

value for chks[0] is 37-C110PDD/L here the value contains slash and is not displaying the required value in span

Code used in script to update value dynamically:

$("#p21stkArwhed_"+chks[0].value).html($("#qohArrVal_"+chks[0].value).val())

Above code working for parameters without SLASH

Any idea how to solve....?

Thank you..........

deepi
  • 1,081
  • 10
  • 18
Warrior
  • 3,184
  • 12
  • 44
  • 53

2 Answers2

2

Using slashes in the attribute ID is illegal. See What are valid values for the id attribute in HTML?

You should replace your slash with a valid character, an hyphen ("-") or an underscore ("_") for example.

Community
  • 1
  • 1
recamshak
  • 854
  • 7
  • 8
0

You can use custom data-* attributes (http://www.w3.org/TR/html5/elements.html#embedding-custom-non-visible-data-with-the-data-attributes), for example:

HTML:

<span data-id="37-C110PDD/L">a span</span>

JS:

alert( $("span[data-id='37-C110PDD/L']").text() );
Kamil
  • 368
  • 1
  • 15