Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将javascript与模型表单一起使用_Javascript_Playframework 2.0 - Fatal编程技术网

将javascript与模型表单一起使用

将javascript与模型表单一起使用,javascript,playframework-2.0,Javascript,Playframework 2.0,我从表单中获取值,并使用这些值在我的play项目中创建旅程对象,但我需要扩展它,以便在背景中添加其他值。下面是我当前的表单,它从用户输入中获取所有值 @form(routes.Application.createJourney()) { <fieldset> @inputText(journeyForm("start_loc"), '_label -> "Starting Location", 'placeholder -> "E.g. 1 Main

我从表单中获取值,并使用这些值在我的play项目中创建旅程对象,但我需要扩展它,以便在背景中添加其他值。下面是我当前的表单,它从用户输入中获取所有值

@form(routes.Application.createJourney()) {

    <fieldset>

    @inputText(journeyForm("start_loc"), '_label -> "Starting Location", 'placeholder -> "E.g. 1 Main Street")
    @inputText(journeyForm("end_loc"), '_label -> "End Location", 'placeholder -> "E.g. 1 High Street")
    @select(
        journeyForm("participant_type"), 
        options = options("Driver"->"Driver", "Passenger"->"Passenger"),
        '_label -> "Travel as",
        '_error -> journeyForm("participant_type").error.map(_.withMessage("Select participant type"))
        )
    @inputDate(journeyForm("date"), '_label -> "Date")
    @helper.input(journeyForm("Time")) { (id,name,value,args) => <input type="time" name="@name" id="@id" @toHtmlArgs(args)> } 

    </fieldset>
    <div class="actions">
        <input type="submit" value="Create" class="btn primary"> 
    </div>
我不确定如何将javascript与这些scala模板生成器一起使用,我有一个javascript函数要使用。我表单中的两个输入是位置,我希望能够使用javascript检索这些位置,使用Google Maps API获取它们的lat/lng值。下面是一个位置的javascript:

  <script type="text/javascript">
  function codeAddress() {
    var geocoder;
    geocoder = new google.maps.Geocoder();
    var address = document.getElementById("address").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        alert(results[0].geometry.location);
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
  }
  </script>

所以有两件事我真的需要做。从表单中检索inputText以用于javascript函数。在我的javascript函数中使用一个变量在后台填充一个表单参数。通常我只需要一个document.getElementByID,但我认为这对正在使用的表单帮助程序不起作用。

您可以使用表单帮助程序设置元素的id。在视图中呈现后,使用javascript检索它应该不会有问题