0

I have a button in a JSP which, when pressed, makes a GET request to a servlet. The following is the link, and it works fine, calling the servlet and correctly passing the id parameter.

<a id="sButton" href="javascript:perform('editShow(/auth/mkt/mgmt/save?id=1)');">
</a>

I need to add another parameter to the GET request. This will be the value entered by the user in an input box, which has an id of newPrefix. I understand that the following JQuery will retrieve the value:

$('#newPrefix').val()

The question is, how to incorporate the above into the HREF.

I have tried the following

<a id="sButton" href="javascript:perform('editShow(/auth/mkt/mgmt/save?newPrefix=$('#newPrefix').val()&amp;id=1)');">
</a>

But this fails. The servlet method is called, but the parameters are not passed correctly.

newPrefix is received as $('

id is received as null

What is the correct way to get the value of the input box within the HREF ?

Thanks

1 Answer 1

1

Anchor with href=javascript: executes javascript function, in your case,

perform('editShow(/auth/mkt/mgmt/save?id=1)');

That means that you will invoke perform with editShow(/auth/mkt/mgmt/save?id=1) as String.

After we understood that, all you need to do is to concat an additional value.

'editShow(/auth/mkt/mgmt/save?id=1&amp;newPrefix=' + $('#newPrefix').val() + ')'

Final code:

<a id="sButton" href="javascript:perform('editShow(/auth/mkt/mgmt/save?id=1&amp;newPrefix=' + $('#newPrefix').val() + ')');">
</a>
Sign up to request clarification or add additional context in comments.

Comments

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.