Note that there are some explanatory texts on larger screens.

plurals
  1. POCalculations in forms using razor (including decimals)
    primarykey
    data
    text
    <p>I am fairly new to all of this and am really struggling to find any examples of what I am trying to do.</p> <p>all I want to create is a simple for where you enter some details and it performs a calculation on it.</p> <p>I can get as far as adding and multiplying etc.. but when it comes to getting a decimal answer out I can get it to work.</p> <p>and as an extra i want to use a drop down as a variable say do one calculation based on the drop down say * 1.4 if its male and * 1.01 if its female</p> <p>below is what I have so far </p> <pre><code>@{ var total = 0; var totalMessage = ""; if(IsPost) { var age_= Request["frmage"]; var weight_ = Request["frmweight"]; var SerCre_ = Request["frmSerCre"]; var sexfactor_ = Request["frmGender"]; var age = age_.AsInt(); var weight= weight_.AsDecimal(); var SerCre = SerCre_.AsDecimal(); total = (((140-age)*weight)*sexfactor)/SerCre ; totalMessage = "Total = " + total; } } &lt;form method="post"&gt; &lt;p&gt;&lt;label for="text1"&gt;Age:&lt;/label&gt; &lt;input type="text" name="frmAge" size="3"/&gt;Years &lt;/p&gt; &lt;p&gt;&lt;label for="text2"&gt;Weight:&lt;/label&gt; &lt;input type="text" name="frmWeight" /&gt;in Kg (1st = 6.35kg) &lt;/p&gt; &lt;p&gt;&lt;label for="text3"&gt;Serum Creatinine:&lt;/label&gt; &lt;input type="text" name="frmSerCre" /&gt; μmol/L &lt;/p&gt; &lt;p&gt;&lt;label for="text4"&gt;Gender:&lt;/label&gt; &lt;select name="frmGender" id="select"&gt; &lt;option value="M" &gt;Male&lt;/option&gt; &lt;option value="F" &gt;Female&lt;/option&gt; &lt;/select&gt; &lt;/p&gt; &lt;p&gt;&lt;input type="submit" value="Calculate" /&gt;&lt;/p&gt; &lt;/form&gt; &lt;p&gt;@totalMessage&lt;/p&gt; </code></pre> <p>some help im probably going about it in the completely wrong way!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload