Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Java by (9.5k points)

Below is my code implementation so far to input a string in a text box and when the user clicks on the submit button, it’ll slice some characters. 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication2.WebForm2" %>

<!DOCTYPE html>

<html xmlns="">

    <head runat="server">



            function Check()


                var inputBox = document.getElementById("TextBox1").value;

                if (inputBox == "") {

                    alert("Enter your full name.");


                var str = inputBox.value;

                var result = str.slice(1, 4);






        <form id="form2" runat="server">




                <td>Enter your full name: </td>


                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>




                <td><button type="button"  onclick="Check()" >Submit</button></td>







Can anyone tell me how to implement the above scenario?

1 Answer

0 votes
by (19.7k points)

Check out the below JQuery implementation:

<asp:TextBox ID="TextBox1" ClientIDMode="Static" runat="server"></asp:TextBox>

<asp:Button ID="Button1" runat="server" Text="Substring(1,4)" />

<script type="text/javascript">

    $(document).ready(function () {

        $('#<% = Button1.ClientID %>').click(function (e) {

            $('#<% = TextBox1.ClientID %>').val(

                            $('#<% = TextBox1.ClientID %>').val().substring(1, 4));

            e.preventDefault(); // prevent PostBack to Server




Interested in Java? Check out this Java Certification by Intellipaat.    

Related questions

0 votes
1 answer
0 votes
1 answer
asked Feb 7, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer

Browse Categories