0

I have a problem with the TextBox. When I was entering duplicate data, it is not allowing. That is what exactly I need but after saving data again it is allowing the duplicate data. How can I handle the scenario?

Here is my code.

var Controls = {
    saveObjectives: function (actionurl) {
        var frm = $('form[name=frmObjectives]')
        frm.attr('action', actionurl);
        frm.submit();
    },
    addObjectiveCheckbox: function () {
        var text = $('#txtObjective').val();
        $('#txtObjective').val('');
        if ($.trim(text) == '')
            return;
        if ($('input[type=checkbox][value="' + text + '"]').length == 0)
        $('#dvObjectives').prepend('<input type="checkbox" name="chkNewobjectives" value="' + text + '" Checked /> ' + text + '<br />');
    },

And my HTML code is:

<input id="btnAddObj" class="btn" type="button" onclick="Controls.addObjectiveCheckbox();" value="Add Objective"/>
      </div> 
    <div id="dvObjectives" name="ObjectivesList">

    @foreach (Andromeda.Core.Entities.Objectives objective in Model)
    {
        <label class="checkbox">
        <input type="checkbox" name="chkobjectives" Checked value="@objective.ObjectiveID" />@objective.ObjectiveText
        </label>
    }
</div>
1
  • Could you try to formulate your question a bit better? I don't think I understand what you want to achieve. Commented May 16, 2013 at 8:58

1 Answer 1

1

You are using value='whatever text` in the jQuery, but value='ObjectiveID' in the view. This should fix it:

<input type="checkbox" name="chkobjectives" Checked value="@objective.ObjectiveText" />@objective.ObjectiveText
Sign up to request clarification or add additional context in comments.

1 Comment

What does the generated html look like from the code I suggested above look like?

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.