0

I have an issue with button click event firing . I have two buttons on same view but for some reason after one one button click other button click event does not fire. Could you any help on this?. If you see below after copydata button click the getdata button click does not fire.

<div id ="MainDiv">
    <table>
        <tr>
            <td>
                <h4> Please Select the Environment :</h4>
            </td>
        </tr>
        <tr>
            <td>
                @Html.DropDownList(
                    "SelectedEnvironmentID",
                    new SelectList(
                        Model.EnvironmentViewModel.Select(x => new { Value = x.Id, Text =  
                        x.Name }),
                        "Value",
                        "Text"), new { @onchange = "HideElements()" }
                    )
            </td>
        </tr>
        <tr>
            <td>
                <h4> Please Select the Version :</h4>
            </td>
        </tr>
        <tr>
            <td>
                @Html.DropDownList(
                    "SelectedVersionID",
                    new SelectList(
                        Model.VersionsModel.Select(x => new { Value = x.Id, Text = x.Number }),
                        "Value",
                        "Text"), new { @onchange = "HideElements()" }
                    )
            </td>
        </tr>
        <tr>
            <td>
                <input id="getData" name="ViewServerData" type="submit" value="View Profiles" />
            </td>
        </tr>

    </table>
</div>

 <p></p>   

 <div id ="ProfileCopyDiv" class="Copy" >
    <table>
        <tr>
            <td>
                <h4> Please Select the Environment To Copy Selected Server Profile:</h4>
            </td>
        </tr>
        <tr>
            <td>
                @Html.DropDownList(
                    "SelectedEnvironmentID2",
                    new SelectList(
                        Model.EnvironmentViewModel.Select(x => new { Value = x.Id, Text = 
                     x.Name }),
                        "Value",
                        "Text"), new { }
                    )
            </td>
        </tr>
        <tr>
            <td>
                <h4> Please Select the Version To Copy Selected Server Profile:</h4>
            </td>
        </tr>
        <tr>
            <td>
                @Html.DropDownList(
                    "SelectedVersionID2",
                    new SelectList(
                        Model.VersionsModel.Select(x => new { Value = x.Id, Text = x.Number }),
                        "Value",
                        "Text"), new { }
                    )
            </td>
        </tr>
        <tr>
            <td>
                <h4> Please Select the PlatformProfile To Copy:</h4>
            </td>
        </tr>

        <tr>
            <td>
                @Html.DropDownList(
                    "SelectedProfileID2", selectList: new SelectList(
                        Model.PlatformProfilewModel.Select(x => new { Value = x.Id, Text = 
              x.Name }),
                        "Value",
                        "Text"), htmlAttributes: new { }
                    )
            </td>
        </tr>
        <tr>
            <td></td>
        </tr>
        <tr>
            <td>  <input id="copyData" name="SnapshotData" type="submit" value="Submit" /> </td>
        </tr>
        <tr>
            <td></td>
        </tr>
    </table>
  </div>
<script type="text/javascript">
    $(function() {
         @grid1.GetJavaScript();
         @grid2.GetJavaScript();

        $("#getData").click(function() {

            alert("Test");
            document.getElementById('gridWrapper1').style.display = 'block';
            document.getElementById('gridWrapper2').style.display = 'block';
            document.getElementById('gridheader').style.display = 'block';
            $('#gridheader').empty();
            //var content = "<table><tr><td><h4>Selected Environment :" +    
              $('#SelectedEnvironmentID :selected').text() + " </h4></td>" +
            //"<td><h4> Selected Version: " + $('#SelectedVersionID :selected').text() 
            + "</h4></td></tr></table>";
            //$('#gridheader').append(content);

            var url = '@Url.Action("GetServersWithSettings")';
            url = url + '?envtid=' + $("#SelectedEnvironmentID").val() + '&versionid=' + 
         $("#SelectedVersionID").val();
            $("#ServersWS").jqGrid('setGridParam', { url: url }).trigger('reloadGrid');
            alert(url);

            var url1 = '@Url.Action("GetServersWithZeroSettings")';
            url1 = url1 + '?envtid=' + $("#SelectedEnvironmentID").val() + '&versionid=' + $("#SelectedVersionID").val();
            $("#ServersWNS").jqGrid('setGridParam', { url: url1 }).trigger('reloadGrid');

            alert(url1);

        });

        $("#copyData").click(function() {

            var selectedRowId = $('#ServersWS').jqGrid('getGridParam', 'selrow');
            var rowData = jQuery("#ServersWS").jqGrid('getRowData', selectedRowId);

            $("#MainDiv *").attr("disabled", false).off('click');
            var url = '@Url.Action("Index")';
            //url = url + '?envtid=' + $("#SelectedEnvironmentID").val() + '&versionid=' + $("#SelectedVersionID").val()
            //              + '&profileid=' + rowData['ProfileId'] + '&envtid2=' + $("#SelectedEnvironmentID2").val() + '&versionid2=' + $("#SelectedVersionID2").val();
            HideElements();
            $.ajax({
                url: url,
                data: {
                            BaseEnvtId: $("#SelectedEnvironmentID").val(),
                            BaseVersionId: $("#SelectedVersionID").val(),
                            BaseProfileId: rowData['ProfileId'],
                            NewEnvtId: $("#SelectedEnvironmentID2").val(),
                            NewVersionId: $("#SelectedVersionID2").val(),
                            NewProfileId: $("#SelectedProfileID2").val(),
                },
                type: 'POST',
                datatype: 'json',
                success: function(data) {
                    //var content = "<div style=/""color: green ;font-weight:900;/"">Baseline Profile Copied Successfully</div>";
                    $("#MainDiv *").attr("disabled", true).off('click');
                    document.getElementById('ProfileCopyDiv').style.display = 'block';
                    $("#MainDiv *").attr("disabled", false).off('click');
                    document.getElementById('displaySuccess').style.display = 'block';
                    $("#ProfileCopyDiv *").attr("disabled", true).off('click');
                    document.getElementById('ProfileCopyDiv').style.display = 'none';
                },
                error: function() { alert('something bad happened'); }
            });



        });

    });
</script>
1
  • You need a form to submit anything to the server! Where's yours? Commented Oct 14, 2013 at 0:32

2 Answers 2

2

If you see below after copydata button click the getdata button click does not fire.

That is because you are disabling the click event on click of copyData for all elements that are descendants of #MainDiv. So this behavior is natural.

     $("#copyData").click(function() {

        var selectedRowId = $('#ServersWS').jqGrid('getGridParam', 'selrow');
        var rowData = jQuery("#ServersWS").jqGrid('getRowData', selectedRowId);

        $("#MainDiv *").attr("disabled", false).off('click'); //<---- HERE
        var url = '@Url.Action("Index")';

Because off turns off event, and here your unfortunate button will be selected by #MainDiv * selector for the click event to be turned off.

Also better use prop instead of attr

Sign up to request clarification or add additional context in comments.

Comments

0

You've probably got some bad javascript in there that's throwing an error, without seeing all of it it's impossible to tell. Try stepping through it in a debugger (use Chrome's developer tools) and see if you get an error message. Maybe it's the HideElements() function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.