locked
Editor box text is always blank RRS feed

  • Question

  • User-1057561109 posted

    I'm trying to retrieve a value from an editor box when the focus changes using ajax.  I want to pull that text and send it as POST data to my handler.

    @using (Html.BeginForm()) {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)
    
        <div class="editor-label">
            @Html.LabelFor(model => model.PipeSize)
        </div>
        <div class="editor-field" id="PipeSize">
             @Html.EditorFor(model => model.PipeSize)
        </div>
    }
    
    <script>
        $("#PipeSize").focusout(function () {
            updateData("ExitHeaderPipeConnSize", ($("#PipeSize").val()))
        });
    
        function updateData(field, numvalue) {
            $.ajax({
                url: "/Eval/UpdateData",
                type: 'Post',
                data: { fieldName: field, fieldValue: numvalue },
                success: function (data) {
                    //do nothing for now
                },
                error: function () {
                    alert("something seems wrong");
                }
            });
        }
    </script>
    
    

    The UpdateData(string fieldName, string fieldValue) Handler inside the Controller updates the data fieldName properly.  But the fieldValue (the text from the editor box) always comes back blank.

    Friday, February 28, 2014 9:56 AM

Answers

  • User-760709272 posted

    PipeSize is the ID given to your div so you'll have two with the same ID.  Give the ID of the div a different value.  When de-bugging javascript issues always look at the source of the page as that is what the js is running from, not your cshtml file.  These problems can often be quickly identified just by looking at the source.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 28, 2014 10:01 AM

All replies

  • User-760709272 posted

    PipeSize is the ID given to your div so you'll have two with the same ID.  Give the ID of the div a different value.  When de-bugging javascript issues always look at the source of the page as that is what the js is running from, not your cshtml file.  These problems can often be quickly identified just by looking at the source.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 28, 2014 10:01 AM
  • User-1057561109 posted

    That was my great big "Duuuurrrrr" moment of the day.  Thanks Aidy.

    Friday, February 28, 2014 2:11 PM