我想写在不同的文本域(罗德和Java)的价值
问题描述:
我使用rhostudio来创建一个移动应用程序。目前我有这种代码我想写在不同的文本域(罗德和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>
的我叫了函数调用一次我把一个文本框button.each有不同的名称和value.same转到按钮和值作为参数的函数调用的值。它支持将call()函数中计算的结果写入特定文本字段。不幸的是,它不!帮助我..
每个文本字段都有不同的名称和它的基础上创建的对象。既然我已经创建了一个基于对象的量多textfilelds,是假设有不同的名称,并将结果写入某个文本框为well.unfortunately,这不!帮助我..
答
你通过了代码的人有很多的错误。不知道你想达到什么目的。
如果你只是想的product.price
和product.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
}
希望这有助于你。