locked
javacript message in between code in button -vb.net RRS feed

  • Question

  • User-1578974752 posted

    I have a save button. which will count the edited number of rows inside the grid view and when I click submit,it will show the count and show the message whether need to proceed or not ,if ok then will submit welse no action.

    Now I want to joint both save and submit code in "submit " button together with count and all.

    so first need to save ,and in between show the count ,then if click ok,then proceed to submit else nothing will happen. How can I call this javascript just after the save and before the submit code. Appreciate the help.

       <script src="../Scripts/jquery-1.10.2.min.js"></script>
        <script type="text/javascript">
            $(function () {
                $("#Update").click(function () {
                        var text = $("#EDITEDVAL").val();  
                    if (confirm("Do you want to proceed? Edited Records for this Number: " + text)) {
                
                        alert("sunbmitted");
                        // the function you need to do
                    } else {
                        return false;
                    }
                });

            })
        </script>

     

    Tuesday, October 29, 2019 10:42 AM

All replies

  • User-1780421697 posted

    You can get the form and submit it by using 

    document.getElementById("YourFome").submit(); on confirmation.

    Tuesday, October 29, 2019 12:31 PM
  • User-1780421697 posted

    Simple example

    <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    
       <script>
           function update()
           {
               var txtValue = $("#EDITEDVAL").val();
               if (confirm("Do you want to proceed? Edited Records for this Number: " + txtValue))
               {
    return true; } else { return false; } } </script> <asp:Textbox ID="txt1" runat="server"></asp:Textbox> <asp:Textbox ID="txt2" runat="server"></asp:Textbox> <%-- I have set 2 as dummy value --%> <input type="text" id="EDITEDVAL" value="2" style="display:none" /> <asp:Button OnClientClick="return update()" OnClick="Save_Click" Text="Save" runat="server" /> </asp:Content>
    public partial class _Default : Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                
    
            }
    
            protected void Save_Click(object sender, EventArgs e)
            {
    
            }
        }

    Tuesday, October 29, 2019 12:40 PM
  • User288213138 posted

    Hi shsu,

    According to your description, I couldn’t understand your requirement clearly.

    shsu

    so first need to save ,and in between show the count ,then if click ok,then proceed to submit else nothing will happen

    This requirement has been implemented in your below code?

    shsu

    How can I call this javascript just after the save and before the submit code

    Which javascript do you want to call?

    shsu

    $("#Update").click(function () {
                        var text = $("#EDITEDVAL").val();  
                    if (confirm("Do you want to proceed? Edited Records for this Number: " + text)) {
                
                        alert("sunbmitted");
                        // the function you need to do
                    } else {
                        return false;
                    }
                });

    What do you want to do with this function?

    So please post more details information about your requirement.

    Best regards,

    Sam

    Wednesday, October 30, 2019 2:41 AM
  • User-1578974752 posted

    I will get the value in the count ("#EDITEDVAL") only if the save command is executed.

    so first save button code,then show the count value ,if Yes the submit button code.

    can this be done in javascript itself. calling 2 buttons before and after messagebox. Thanks

    At present : Save button will save the values. Then if I click submit button ,then the count of the saved row will be shown,if user click ok ,then will submit else cancelled. below code is working.

    if I clicked the save button it will save the rows . If I click submit button, then first it will show the count (saved) as message then ,if user click ok,will submit.

    $("#Update").click(function () {
                        var text = $("#EDITEDVAL").val();  
                    if (confirm("Do you want to proceed? Edited Records for this Number: " + text)) {
                
                        alert("sunbmitted");
                    
                    } else {
                        return false;
                    }
                });

    Wednesday, October 30, 2019 5:58 AM
  • User288213138 posted

    Hi shsu,

    I will get the value in the count ("#EDITEDVAL") only if the save command is executed.
    so first save button code,then show the count value ,if Yes the submit button code.
    can this be done in javascript itself. calling 2 buttons before and after messagebox. Thanks
    
    At present : Save button will save the values. Then if I click submit button ,then the count of the saved row will be shown,if user click ok ,then will submit else cancelled. below code is working.
    if I clicked the save button it will save the rows . If I click submit button, then first it will show the count (saved) as message then ,if user click ok,will submit.

    I am very sorry, I still can't understand what you mean.

    Do you want to click the submit button, first execute the save button code, then show the count value, then if you click ok, then alert sunbmitted?

    If so, you can refer to below code:

    <script type="text/javascript">
            function save() {
                //your save button code
                var text = $("#EDITEDVAL").val();
                alert("Edited Records for this Number: " + text);
            }
            $(function () {      
                $("#submit").click(function () {
                    var text = $("#EDITEDVAL").val();
                    if (confirm("Do you want to proceed? Edited Records for this Number: " + $("#EDITEDVAL").val())) {
    
                        alert("sunbmitted");
                        // the function you need to do
                    }
                    else
                    {
                        return false;
                    }
                });
    
            })
        </script>
    
    
    <input id="Save" type="button" value="Save" onclick="save()" />
                <input id="submit" type="button" value="submit" />
                <asp:TextBox ID="EDITEDVAL" runat="server" Text="5"></asp:TextBox>

    The result:

    If I misunderstand your requirement, please post more details information about your requirement. or please post your save code and submit code.

    Best regards,

    sam

    Wednesday, October 30, 2019 8:56 AM
  • Thursday, October 31, 2019 8:03 AM