2013-09-25 1 views
0

저는 rhostudio를 사용하여 모바일 앱을 만듭니다. 현재 나는 내가 button.each의 텍스트 필드를 누르면 일단 내가 다른 이름을 가지고 value.same은 함수 호출에 대한 매개 변수로 버튼 값의 값으로가는 함수 호출을 호출 코드다른 텍스트 필드 (rhodes 및 java)에 값을 쓰고 싶습니다

<div data-role="page"> 

<script type="text/javascript"> 
function call(harga,nama){ 

var quantity=prompt("Insert Quantity"); 
var pri=harga; 
var nam="document.form1."+nama; 
alert("unit price RM" + pri+".00"); 
price= quantity * pri; 
alert(quantity); 
alert("total price RM" + price+".00"); 
alert("total price RM" + price+".00" + " should be displayed into " + nam +" textfield"); 
document.form1."name".value = quantity; 
nam.value = quantity; 
document.form1."name".value = "RM " + price; 
// document.form1.hidden3.value = nam; 
} 
</script> 

<div data-role="header" data-position="inline"> 
<h1>Displays</h1> 
<a href="<%= Rho::RhoConfig.start_path %>" class="ui-btn-left" data-icon="home" data-direction="reverse" <%= "data-ajax='false'" if is_bb6 %>> 
    Home 
</a> 
<a href="<%= url_for :action => :new %>" class="ui-btn-right" data-icon="plus"> 
    New 
</a> 
</div> 

<div data-role="content"> 

    <form name="form1"> 
    <table> 
        <tr align="center"> 
        <td>Product</td> 
        <td>Quantity</td> 
        <td>Total Price</td></tr> 
    <% @products.each do |product| %> 
        <tr align="center"> 
        <td><%= product.name %></td> 
        <td><input type="text" name="<%= product.name %>" value="textfield <%= product.name %>"></td> 
        <td><input type="text" name="<%= product.price %>" value="textfield <%= product.price %>"></td> 
        </tr> 
    <% end %> 
        </table> 
<br/> 
    <br/> 

    <% @products.each do |product| %> 


    <input type="hidden" value="price :<%= product.price %>" name="harga"/> 
    <input type="button" onclick="call(<%= product.price%>,value);" name="Press" value="<%= product.name %>"> 




    <% end %> 





    </form> 
</div> 

</div> 

의 종류가 않습니다. call() 함수로 계산 된 결과를 특정 텍스트 필드에 쓰는 것을 권장합니다. 불행히도, 그렇지 않습니다! 도와주세요 ..

각 텍스트 필드는 다른 이름을 가지고 있으며 생성 된 개체를 기반으로합니다. 왜냐하면 나는 많은 텍스트 파일을 개체의 양을 기반으로 만들었습니다, 다른 이름을 가지고 그 텍스트 필드에 결과를 작성하는 것입니다. 불행히도, 그것을하지 않습니다! 도와주세요 ..

답변

0

당신은 코드 맨 밖으로 많은 오류가 있습니다. 무엇을 성취하려고하는지 모릅니다.

그냥 call 기능에 product.priceproduct.name의 값을 전달하려면

, 다음과 같은 기능에 다음이 당신을 도와줍니다

function call(harga,nama){ 

    var quantity=prompt("Insert Quantity"); 
    quantity = isNaN(parseFloat(quantity)) ? 0 : parseFloat(quantity); 
    var pri = isNaN(parseFloat(harga)) ? 0 : parseFloat(harga); 
    alert("unit price RM" + pri); 
    var price= quantity * pri; 
    alert("total price : " + price); 

    // specify your rest code over here 

} 

희망이

<input type="button" onclick="call('<%= product.price %>','<%= product.price %>');" value="Press" /> 

을 시도합니다.