2013-03-11 2 views
1

양식에서 값을 가져 와서이 값을 사용하여 내 게임 프로젝트에서 Journey 개체를 만들지 만 배경에 값을 추가 할 수 있도록이 값을 확장해야합니다. 아래는 사용자 입력에서 모든 값을 가져 오는 현재 양식입니다.자바 스크립트를 사용하여 모델 양식

@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> 

나는 당신이 스칼라 템플릿 생성기 자바 스크립트를 사용하는 방법을 정말 잘 모르겠어요 그리고 내가 사용하고자하는 자바 스크립트 함수가 있습니다. 내 양식의 입력 중 2 가지는 위치에 대한 것이며, 자바 스크립트로 해당 위치를 검색하여 Google Maps API를 사용하여 위도/경도 값을 가져올 수 있기를 원합니다. 아래는 하나의 위치에 대한 자바 스크립트입니다 :

<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를 검색하십시오. 자바 스크립트 함수에서 변수를 사용하여 백그라운드에서 폼 arguements 중 하나를 채 웁니다. 일반적으로 난 그냥 document.getElementByID 것이라고하지만이 게임에서 양식 도우미 함께 작동하지 것 같아?

답변

0

양식 도우미를 사용하여 요소의 ID를 설정할 수 있습니다. 보기에서 렌더링 된 자바 스크립트로 검색하는 것이 좋을 것입니다.

관련 문제