0

HTML :

<input type="radio" onclick="radioCall(${item.label})" name="radioPurpose" id="${item.value}" value="${item.value}"/>&nbsp; <c:out value="${item.label}" />

Js :

function radioCall(radioValue){
    alert(radioValue.value);
}

I am not able to see the alert with texts which have space in between. It worked for one option which was one full text word. I have tried with double quotes as escape characters for values however the value doesnt appear in the alert. Instead i get javascript errors like SyntaxError: missing ) after argument list. Some of my options have brackets as well. any solution for this?

${item.label} usually has values like:

  • Please try to help me!
  • You are not 'the' (only) one
  • I am not sure (unsure) about what you want.

@Blaze, heres the HTML

<li>
<input id="SELECT" type="radio" value="SELECT" name="radioPurpose" onclick="radioCall(SELECT)">
  SELECT
</li>
<li>
<input id="1" type="radio" value="1" name="radioPurpose" onclick="radioCall(S22 (2)(a) More Security)">
  S22 (2)(a) More Security
</li>
<li>
<input id="14" type="radio" value="14" name="radioPurpose" onclick="radioCall(testtestte)">
  testtestte
</li>

In above 3 options, only SELECT is displayed in the alert. All other options give me javascript errors.

Aman Mohammed
  • 2,878
  • 5
  • 25
  • 39
  • 1
    Please show us the rendered HTML, not the server-side code. – Blazemonger Aug 10 '15 at 19:23
  • @Blazemonger, i have edited my post to share the rendered HTML – Aman Mohammed Aug 10 '15 at 19:29
  • 2
    Let's forget JSP for now. How exactly would you call a JavaScript function with a String as argument? Once you figure out that, just rewrite JSP code in such way that it produces exactly the desired HTML/JS output. – BalusC Aug 10 '15 at 19:30
  • @BalusC somtimes criticism can do wonders. I just changed the HTML code to radioCall( '${item.label}' ) and it worked. Thanks guys! – Aman Mohammed Aug 10 '15 at 19:52

0 Answers0