Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing script after validation

I'm trying to validate all the textboxes to make sure they are all filled before allowing a user to proceed. I've got 2 buttons involved. The first button is sent to javascipt, to validate, and the second to vb.net to upload files and save the details into database. Each button is working perfectly if I manually click them. the problem is, I cant get them to work together. (IE. Press the first button to initiate javascript check, if successful, call button 2 to initiate vb.net script to add to database and redirect. )

this is the validation script (in javascript)

function fnCheck() {

        if ((document.getElementById("price").value).length > 0) {
            var r = confirm("Are you sure the details are correct?");
            if (r == true) {
                document.getElementById("Submit1");
            }
            else {
                x = "You pressed Cancel!";
            } 

        }


    }

and this a sample of my vb.net textbox + code (not using codebehind)

<script runat="server">

    Sub SubmitButton_Click(Source As Object, e As EventArgs)

        Response.Redirect("../services.html")
    End Sub

</script>

<asp:TextBox ID="price" runat="server" CausesValidation="true"></asp:TextBox>

<input id="Submit1" runat="Server" onserverclick="SubmitButton_Click" 
                            type="submit" value="Upload Files" />
<asp:Button ID="Button5" runat="server" Text="1" 
                                OnClientClick="javascript:return fnCheck()"/>

Please help. Thanks!

like image 959
AndrewTsang Avatar asked Aug 01 '26 06:08

AndrewTsang


1 Answers

ALthough I'm not familiar with vb.net spirit, but if you are trying to simulate a click event on the <input> element, try the following:

Change input type to button:

<input id="Submit1" runat="Server" onserverclick="SubmitButton_Click" 
                        type="button" value="Upload Files" />

Invoque the click() method on the button element:

function fnCheck() {

    if ((document.getElementById("price").value).length > 0) {
        var r = confirm("Are you sure the details are correct?");
        if (r == true) {
            document.getElementById('Submit1').click();
        }
        else {
            x = "You pressed Cancel!";
        } 

    }


}
like image 70
tmarwen Avatar answered Aug 02 '26 18:08

tmarwen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!