1

So I have an issue that I'm not 100% sure on how to solve. Im looping through a list of strings and creating multiple forms, what I want to do is set the id of the elements to the string minus spaces. I have a javascript function to remove the spaces

function trimWhiteSpaces(name) {
return name.replace(/\s+/g, '');
}

and below is my current code for generating the forms:

@(name: List[String])

...

@for(name <- names) {
        <td>@name
        @form(routes.Application.makeCall()) {
        <div id="hiddenForm" style="visibility:hidden">
            <input type="text" name="commandID" id="id@name" value="10" />
            <input type="text" name="source" id="sourceCall@name" value="source" />
            <input type="text" name="destination" id="dest@name" value="@name" />
        </div>
        <input type="submit" value="Call" id="call@name"/>
        }
}

but what I would like to do is: is something like:

<input type="submit" value="Call" id="call{js:timWhiteSpaces(@name)}"/>

Any help would be appreciated. The other option I have thought that would work would be instead of passing strings pass a new custom objects that has two options. But as I'm not an expert at html/javascript i was wondering if there was a way to do it in javascript?

1 Answer 1

3

I would suggest you do it on the server side, as in

id="@(name.replace(" ", ""))"
Sign up to request clarification or add additional context in comments.

1 Comment

cool thank you very much. i was abloe to use the following and it worked: <input type="text" name="source" id="@name.replace(" ","")" value="source" />

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.