Shomen Deb

Shomen Deb

  • NA
  • 43
  • 0

Generate Random Number in javascript & display in @Html.Editfor/@Html.Textboxfor

May 27 2012 6:06 AM
Hello,

I am developing a small project using Asp.net MVC3. I would like to generate a random number using javascript and send this number to @Html.Editfor or @Html.TextBoxfor. I can generate random number but I cannot pass this value to html textbox to display.

My code is like that:
@using (Html.BeginForm())
{
      <div class="editor-field">
            @Html.EditorFor(model => model.TrackingID)
            @Html.ValidationMessageFor(model => model.TrackingID)                    
                <input type="button" value="Filter" onclick="randomNumbers()"/>
       </div>
}


Javascript:

<script type="text/javascript">
    function randomNumbers() {
        // Math.floor(Math.random() * (UpperRange - LowerRange + 1)) + LowerRange; Generate within a range
        var str = Math.floor(Math.random()*100);
       
        document.getElementById('TrackingID') = str;  
       
    }
</script>


Please help me.


Regards,
Shomen

Answers (2)