Home > Blockchain >  Thymeaf Calculated URL Value
Thymeaf Calculated URL Value

Time:10-25

I need to get a value from the select component of my page and set its value as a parameter in the href.

<td ><a th:href="@{/export(exportEntity='Person',semester='javascript:document.getElementById(\'semester\').value')}">Download</a></td>

Semeter variable has the value at my server side:

semester = javascript:document.getElementById('semester').value 

and not the dropdown value.

Unfortunately, this code is not picking the value from the select component. Any guess what I have done wrong here.

CodePudding user response:

Thymeleaf runs on the server, while JavaScript runs on the browser. You can't mix it like that.

It's difficult to say what to do, because your question is lacking context, specifically: What is the element with the id semester?

If it's a select element (or another form element), then it would be possible to use neither Thymeleaf nor JavaScript, but a simple form:

<form method="get" action="/export">
  <input type="hidden" name="exportEntity" value="Person">
  <select name="semester">
    <option value="A">Semester A</option>
    <option value="B">Semester B</option>
  </select>
  <input type="submit" value="Download">
</form>

Clicking on the button will have the browser generate an URL such as /export?exportEntity=Person&semester=A and go to it.

  • Related