NoIdea.Net 0 Newbie Poster

Hello people!

I have a strange problem in the code below.

It runs fine with the new value being use/displayed but on all the following executions it will onbly use the values from the first run whatever you type in.

Any ideas?

Thanks

<script type="text/javascript">
    function showEthnicityDialog(eth_desc, eth_code, id) {
        var $dialog=null;
        $dialog = $('<div></div>')
            .html('<script src="/Scripts/jquery.validate.min.js" type="text/javascript"><' + '/script>' +
                    '<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></' + 'script>' +
                    '<form action="/Ethnicity/edit" method="post">' +
                    '<fieldset>' +
                    '<legend>Ethnicity</legend>' +
                    '<label for="Ethnicity1">Ethnicity Description</label>' +
                    '<input class="text-box single-line" id="New_Ethnicity" name="New_Ethnicity" type="text" value="' + eth_desc + '" />' +
                    '<div class="editor-label">' +
                    '<label for="Code">Code</label>' +
                    '</div>' +
                    '<div class="editor-field">' +
                    '<input class="text-box single-line" id="New_Code" name="New_Code" value="' + eth_code + '" type="text"  />' +
                    '<span class="field-validation-valid" data-valmsg-for="Code" data-valmsg-replace="true"></span>' +
                    '</div>' +
                    '<input type="submit" id="submit_ethnicity" style="visibility: hidden" value="Save" />' +
                    '</fieldset>' +
                    '<p></p>' +
                    '</form>')

            .dialog({
                autoOpen: false,
                overlay: { opacity: 0.1, background: 'Black' },
                buttons: {
                    'Save': function () {

                        function ethnicity(eth, code) {
                            this.Ethnicity1 = eth;
                            this.Code = code
                        };

                        var new_code = $('#New_Code').val();
                        var new_desc = $('#New_Ethnicity').val();
                        alert("Before values: " + new_code + "/ " + new_desc); // Always the value from the first run!
                        var code_marker = '#code_' + id;
                        var values = new ethnicity(new_desc, new_code);

                        alert(values.Ethnicity1 + "/" + values.Code);
                        $.post('@Url.Action("/edit")', values, function (data) { });

                        // setTimeout(function () { }, 1000)
                        // $.post('@Url.Action("/readCodeFromDB")', { 'key': eth_desc }, function (data) { $(code_marker).html(data); });
                        $(code_marker).html($('#New_Code').val());
                        delete new_code;
                        delete new_desc;
                        delete values;
                        $(this).dialog('destroy');
                    },
                    'Cancel': function () {
                        $(this).dialog('destroy');
                    }
                },
                modal: true,
                closeOnEscape: true,
                width: 520,
                resizable: false,
                title: "Edit: " + eth_desc,
                show: { effect: "fade", speed: "slow" },
                hide: { effect: "fade", speed: "slow" }
            });

        $dialog.dialog('open');

        //return false //cancel eventbubbeling
    };
</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.