Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8166185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:46:30+00:00 2026-06-06T19:46:30+00:00

I have the code below which I use clone() and delegate() . The code

  • 0

I have the code below which I use clone() and delegate().
The code is being load in a jQuery UI dialog with a link.
the problem is Ajax being triggered properly, and it calls to success methods as it supposed but none of Ok or noOk divs are being shown, I mean the alerts trigger but the css of divs don’t change, Where do you think my problem is? is there something wrong with selectors? thanks

    <input id="TaskId" name="TaskId" type="hidden" value="18" />
    <div id="MainDiv">
        <div id="toClone">
            <div style="display: inline;">
                <select id="Tasksess">
                    <option value="">لطفاً کار را انتخاب کنيد</option>
                    <optgroup label="کار های جديد">
                            <option value="16"style="">q3fe</option>
                            <option value="18"style="">fjhv j</option>
                            <option value="19"style="">wref</option>
                            <option value="25"style="">ff</option>
                    </optgroup>
                    <optgroup label="کار های در دست اقدام">
                            <option value="13"style="">rr</option>
                            <option value="15"style="">yy</option>
                    </optgroup>
                    <optgroup label="کار های تمام شده">
                            <option value="14"style="">tt</option>
                            <option value="18"style="">fjhv j</option>
                    </optgroup>
                </select>
            </div>
            <div style="display: inline;">
                <select id="Statusess" name="Statusess">
                    <option value="">لطفاً وابستگی را انتخاب کنيد</option>
                    <option value="1">پيشنياز</option>
                    <option value="2">همنياز</option>
                </select>
            </div>
            <div style="display: none;" id="Ok">
                ok
            </div>
            <div style="display: none;" id="noOk">
                تکراری
            </div>
            <div id="loadingGif" style="display: none;">
                <img src="/Content/Images/ajax-loader/253L.gif" alt=""/>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {

            var Maindiv = $("#MainDiv");
            var toClone = $("#toClone");

            //$("#Statusess").each(function () {
                $("#MainDiv").delegate('#Statusess', 'change', function () {
                    if ($(this).find(":selected").val() != "") {                    
                        if ($(this).parent().prev().find(":selected").val() != "") {
                            $(this).parent().parent().find("#loadingGif").attr("style", "display: inline;");
                            $.ajax({
                                url: '/ProjectAdmin/Project/AddTaskDependency?MainTaskId=' + $("#TaskId").val() + '&DependentTaskId=' + $(this).parent().prev().find(":selected").val() + '&Status=' + $(this).find(":selected").val(),
                                type: 'GET',
                                success: function (data, status) {
                                    if (data != "0") {
                                        $(this).parent().parent().find("#Ok").css('display', 'inline');
                                        $(this).parent().parent().find("#noOk").css('display', 'none');
  alert("1");
                                    }
                                    else if (data == "0") {
                                        $(this).parent().parent().find("#Ok").css('display', 'none');
                                        $(this).parent().parent().find("#noOk").css('display', 'inline');
  alert("2");
                                    }
                                    var div = $('div:eq(0)', Maindiv).clone();
                                    Maindiv.append(div);
                                }
                            });
                            $(this).parent().parent().find("#loadingGif").attr("style", "display: none;");

                        }
                    }
                });
            //});

        });
    </script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:46:33+00:00Added an answer on June 6, 2026 at 7:46 pm

    I believe your main problem is in your selectors, yes. You can add extra alerts to spit out values at each reference to see where it goes wrong.

    I got irritated with that method so I made some changes to your setup and (aside from the ajax piece that I can’t test without having your AskTaskDependancy file) got it working I believe as you expected.

    First off, the jsFiddle

    Note: I changed all the text to english. This has no bearing on your code, I’m just illiterate in not-english, so feel free to change it back as it has no effect on the code.

    The change log

    • Added error alert()s if a select‘s value is empty
    • $(this).find(":selected").val() to simply $(this).val()
    • several of the reference names to camelCase
    • all IDs inside the MainDiv to classes
    • moved class name from the select elements to the div holding each
    • .parent.prev() to .parent.children(".tasksess") (and similar reference scheme for other elements)
    • set a var for easy reference to each div/select
    • changed css() to attr() (for hiding/showing ok/notOk)
    • I built the ajax url on separate lines for easier reading.
    • Moved the clone() outside of the ajax request to verify that it works (feel free to move it back as needed – be aware the loadingGif which remains shown in each copy if you don’t hide it first)
    • commented out the ajax request for testing

    The new HTML

    <input id="TaskId" name="TaskId" type="hidden" value="18" />
    <div id="MainDiv">
        <div class="toClone">
            <div class="tasksess" style="display: inline;">
                <select name="tasksess">
                    <option value="">Select a Task</option>
                    <optgroup label="Group 1">
                            <option value="16"style="">q3fe</option>
                            <option value="18"style="">fjhv j</option>
                            <option value="19"style="">wref</option>
                            <option value="25"style="">ff</option>
                    </optgroup>
                    <optgroup label="Group 2">
                            <option value="13"style="">rr</option>
                            <option value="15"style="">yy</option>
                    </optgroup>
                    <optgroup label="Group 3">
                            <option value="14"style="">tt</option>
                            <option value="18"style="">fjhv j</option>
                    </optgroup>
                </select>
            </div>
            <div class="statusess" style="display: inline;">
                <select name="statusess">
                    <option value="">Select a Status</option>
                    <option value="1">opt8</option>
                    <option value="2">opt9</option>
                </select>
            </div>
            <div class="ok" style="display: none;">
                Everything looks good!
            </div>
            <div class="notOk" style="display: none;">
                Something went wrong!
            </div>
            <div class="loadingGif" style="display: none;">
                Loading...
                <img src="/Content/Images/ajax-loader/253L.gif" alt=""/>
            </div>
        </div>
    </div>​
    

    The new jQuery/JavaScript

    $(document).ready(function () {
    
        var Maindiv = $("#MainDiv");
        var toClone = $(".toClone");
    
        $("#MainDiv").delegate('.statusess', 'change', function () {
            var thisSel = $(this).children("select");
            var prevSel = $(this).parent().children(".tasksess").children("select");
            var divOk = $(this).parent().children(".ok");
            var divNotOk = $(this).parent().children(".notOk");
            var divLoad = $(this).parent().children(".loadingGif");
    
            if (thisSel.val() != "") {
                console.log("status changed to val " + thisSel.val());
                if (prevSel.val() != "") {
                    console.log("task is val "+prevSel.val());
    
                    divLoad.attr("style", "display: inline;");
                    var url = '/ProjectAdmin/Project/AddTaskDependency';
                    url += '?MainTaskId=' + $("#TaskId").val();
                    url += '&DependentTaskId=' + prevSel.val();
                    url += '&Status=' + thisSel.val();
                    console.log("URL= "+url);
                    /*
                    $.ajax({
                        url: url, type: 'GET',
                        success: function (data, status) {
                            if (data != "0") {
                                divOk.attr("style","display:inline;");
                                divNotOk.attr("style","display:none;");
                            }
                            else if (data == "0") {
                                divOk.attr("style","display:none;");
                                divNotOk.attr("style","display:inline;");
                            }
                        }
                    });
                    */
                    divLoad.attr("style", "display: none;");
                    var div = $('div:eq(0)', Maindiv).clone();
                    Maindiv.append(div);
    
                } else { alert("Select 1 val is empty"); }
            } else { alert("Select 2 val is empty"); }
        });
    
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the code below which I use clone() and live() . The code
I have the following code below which works, but I want to insert values
I have wrote the code below which was taken from Java How to program
I have below code which overrides equals() and hashcode() methods. public boolean equals(Object obj)
I have a working JavaScript code below which dynamically creates JSON object using JSON.parse
I have a function(please see code below) which reads some data from the web.
I have a piece of matlab code below which reads data from a table.
I have a C extension (code below) in which I'm trying to get access
I have the code below, which works fine it can be viewed for an
I have the code below which I am using to upload files to my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.