I am new to programming in general and jquery in particular. I am building an ASP MVC project that uses the following plugin for a star rating system:
https://github.com/kartik-v/bootstrap-star-rating
However, I am having a difficult time accessing the value for the database once the user selects a rating. My current code is as follows:
<div class="form-group">
@Html.LabelFor(model => model.Rating, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<span class="star">
<input id="input-id" type="radio" value="alert($('input#input-id').val())" class="rating" data-size="lg">
</span>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet">
<link href="~/Content/star-rating.css" media="all" rel="stylesheet" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.js"></script>
<script src="~/Scripts/star-rating.js" type="text/javascript"></script>
<link href="~/Content/theme-krajee-svg.css" media="all" rel="stylesheet" type="text/css" />
<script src="~/Scripts/theme-krajee-svg.js"></script>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
When I inspect the HTML after loading the page, I can see that the plugin changes:
<input id="input-id" type="radio" value="alert($('input#input-id').val())" class="rating" data-size="lg">
To:
<input id="input-id" type="radio" value=//whatever user rates class="rating hide" data-size="lg">
So it seems maybe I am returning some type of hidden input? I read this link, but nothing worked:
jQuery access input hidden value
I must be doing something wrong. Any help would be much appreciate by this novice!