0

i'm using rhostudio to create a mobile app. currently i do have this kind of codes

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

i called a function call once i pressed a button.each textfield have different name and value.same goes to the value of the button and value as parameter for function call. it suppost to write the result calculated in the call() function into the specific textfield. unfortunately, it does not! help me..

each text field has different name and it based on object created. since i have created many textfilelds based on the amount of object, is suppose to have different name and write the result into that textfield as well.unfortunately, it does not! help me..

1 Answers1

0

You have lots of error through out the code man. Don't know what are you trying to achieve.

If you just want to pass the values of product.price and product.name to the call function, try this

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

Then on the function like below,

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 

}

Hope this helps you.

Ashis Kumar
  • 6,494
  • 2
  • 21
  • 36