How to define the value of the shape with the external selection value

advertisements

so i am using the play framework and I'm try to create multiple submit buttons that call the one form:

So what I have is a list of strings, and i would like to create two buttons that will go back to the server and complete an event, the first is send the second is cancel. What i would like to also do is set the source value equal to what is selected in the foo select object. How would I go about doing this? Do i need to create a javascript even that is fired from the form and then get the var inside that function and then fire off the submit? Im not 100% familiar with play framework and scala, so im not sure if i can get it somehow inside this code without using a new method.

@(myList: List[String], theForm: Form[Obj])
@import helper._
@main("myVar Controller") {

<select id="foo">
</select>

<table border="1">
    <tr>
    @for(myVar <- myList) {
        <td>@myVar
        @form(routes.Application.method()) {
        <div id="hiddenForm" style="visibility:hidden">
            <input type="text" name="commandID" id="commandID" value="10" />    //Send Code
            <input type="text" name="source" id="source" value=**"Put selected value of foo here" />**
            <input type="text" name="destination" id="destination" value="@myVar" />
        </div>
        <input type="submit" value="Send" />
        }
        @form(routes.Application.method()) {
        <div id="hiddenForm" style="visibility:hidden">
            <input type="text" name="commandID" id="commandID" value="18" />    //Undo code
            <input type="text" name="source" id="source" value=**"Put selected value of foo here" />**
            <input type="text" name="destination" id="destination" value="@myVar" />
        </div>
        <input type="submit" value="Undo" />
        }
        </td>
    }
    </tr>
</table>

}


First of all, the html isn't valid. You should first make sure that there aren't elements that have the same id.

You have to use javascript to change a value in your form. I'm not familiar with scalar or playframework, but if they allow you to use jQuery, I recommend the following solution.

$("#foo").bind("change", function(){$("#source").val($("#foo").val()));});​

example: http://jsfiddle.net/RubenJonker/a8a8p/5

If they don't allow you to use jQuery, then you should put some javascript in the onchange event of the select.

<select onchange="document.getElementById('source').value = this.value">
</select>

example: http://jsfiddle.net/RubenJonker/a8a8p/4