0

I try to dynamically change value of its variable. Once onclick (Change Ticket ID ) button then execute onClickSendEmail and variable value should be change of tickedId. Its unable to update with newTickedId. I tried while create variable using @defining and individual calling by function also. So, Basically I got stuck. how it will be solve.

@(sender: String)
<!--@{var tickedId = "tickedId"}-->


@defining(sender.contains("@")) {isEmail =>
@main((if(isEmail) "Email" else "Chat") + " Messages - " + sender) {

    ...
    ...
    ...
<div>
 <a onclick="onClickSendEmail();return false;">
            Change Ticket ID
     </a>
</div>

@defining("getTicketId()") { tickedId =>

        @views.html.common.form.panel("Reply",controllers.routes.ChatMessageController.sendEmail(tickedId,sender),"Send"){
                <textarea id="emailArea" cols="100" rows="4" name="emailArea"></textarea>
        }


<script type="text/javascript">
            function onClickSendEmail() {
                tickedId= "NewUpdatedTicketId";
            }
     function getTicketId() {
             return "NewUpdatedTicketId";
            }
    </script>
 }
}
}
Vinod
  • 300
  • 3
  • 18

1 Answers1

1

You should not mix Twirl templating with Javascript. It's a bad approach. The role for Twirl is to render HTML blocks. You can define conditions and variables here in order to dynamically change the HTML output. While with Javascript you can modify this rendered HTML output without reloading the page.
There are cases where you need to use a Twirl variable in Javascript, then you can do something like:

@(chartData: Html)

<script>
    let jsData = @twirlData; // where twirlData is an existing variable
    console.log(jsData)
</script>


Here's a link where you can read more.

Csaba
  • 421
  • 4
  • 8