Monday, 11 January 2021

MVC - jQuery - Check if strings contains specified text (substring)

 Watch this example on YouTube


 

@model WebApplication1.Models.OrderCustomClass


@using (Html.BeginForm("Index", "Home"))
{
    @Html.TextBoxFor(x=>x.or.Column1, new { @id = "test" })

}
<input type="submit" onclick="DoSomething()" value="check if string exists" />
@section Scripts{
    <script type="text/javascript">
        function DoSomething() {
            var test = $("#test").val();
            if (test.indexOf("abc") >= 0) {
                alert("found")
            }
            else {
                alert ("not found")
            }
        }
    </script>    
}
 

No comments:

Post a Comment