質問

I have functions in javascripts as

$(document).ready(function () {
        if ($("#ProductName").val().toString() == "") {
            $("#pricingSectionDisplay").hide;
            $("#pricingSectionProductName").val("");
        }
        else {
            $("#pricingSectionDisplay").show;
            $("#pricingSectionProductName").val($("#ProductName").val());
        }


        if ($("#PackSize").val().toString() == "") {
            $("#pricingSectionDisplay").hide;
            $("#pricingSectionPackSize").val("");
        }
        else {
            $("#pricingSectionDisplay").show;
            $("#pricingSectionPackSize").val($("#PackSize").val());
        }
    });

 function pricingSectionDisplay() {
        if ($("#ProductName").val().toString() == "") {
            $("#pricingSectionDisplay").hide;
            $("#pricingSectionProductName").val("");
        }
        else {
            $("#pricingSectionProductName").val($("#ProductName").val());
        }

        if ($("#PackSize").val().toString() == "") {
            $("#pricingSectionDisplay").hide;
            $("#pricingSectionPackSize").val("");
        }
        else {
            $("#pricingSectionPackSize").val($(PackSize).val());
        }
    }

Actually I need to fill in labels , having id pricingSectionProductName and pricingSectionPackSize when textboxes

  @Html.TextBoxFor(m => m.ProductName, new { @class = "form-control", @id = "ProductName", onblur = "pricingSectionDisplay()" })

and

@Html.TextBoxFor(m => m.PackSize, new { @class = "form-control", @id = "PackSize", onblur = "pricingSectionDisplay()" })

are filled.

My codes does not seem to achieve this. What did I do wrong?

役に立ちましたか?

解決

All your method calls like this:

$("#pricingSectionDisplay").hide;

should be:

 $("#pricingSectionDisplay").hide();

Also, .val() already returns a string so there's no reason to call .toString() on it.


If you need further help, please post the actual relevant HTML (what the browser sees with view/source, not a template).

他のヒント

The id of your helper should be id='...'. You don't need to add an @ because id is not a reserved keyword. so write

 @Html.TextBoxFor(m => m.ProductName, 
     new { @class = "form-control", id = "ProductName", 
      onblur = "pricingSectionDisplay()" })

instead of

  @Html.TextBoxFor(m => m.ProductName, 
              new { @id = "ProductName", 
                    onblur = "pricingSectionDisplay()" })

In addition You must call show method like this show() and not show The same with hide, write hide() instead of hide

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top