我想在不同的文本字段(Rhodes和Java)中写入值

i want to write value in different textfield (rhodes and java)

本文关键字:Java Rhodes 字段 文本      更新时间:2023-09-26

我正在使用RhoStudio创建一个移动应用程序。 目前我确实有这种代码

<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(( 函数中计算的结果写入特定的文本字段。 不幸的是,它没有! 帮帮我..

每个文本字段都有不同的名称,

并且它基于创建的对象。由于我已经根据对象的数量创建了许多 textfilelds,因此假设具有不同的名称并将结果也写入该文本字段。不幸的是,它没有! 帮助我..

你在整个代码人中有很多错误。 不知道你想实现什么。

如果您只想将 product.priceproduct.name 的值传递给 call 函数,请尝试此操作

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

然后在下面这样的函数上,

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 
}

希望这对你有帮助。