Solved

Getting class set textbox value?

Posted on 2015-02-04
3
79 Views
Last Modified: 2015-02-10
Hello all,

I have some code that I use to set a read only textbox value such as this:

@Html.TextBoxFor(model => model.OriginalValue, new { @class = "setOrigVal k-textbox", @disabled = "true", style = "width: 110px; background-color:#eee" })

When this happens in an ajax post I can properly set the value to the control that shows on the UI in the textbox:
 $(".setOrigVal").val(resp.OriginalValue);

Problem is when I go to get the value its showing "".   How can I handle this to get the value set?

This is what I am doing:
var tbOrigValue = $(".setOrigVal").val();

but its "".
0
Comment
Question by:sbornstein2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 40588882
Can you show the code for how you are making the ajax call, and setting the control with the result?
0
 

Author Comment

by:sbornstein2
ID: 40588993
Sure thing:

Here it is:

 function getOriginalValue() {
        debugger;
        var dsDropDownLst = $("#DataSourceDropDown").data("kendoDropDownList");
        var dtMarketValue = $("#MVDate").data("kendoDatePicker");

        if (dsDropDownLst.value() > 0 && dtMarketValue.value() != null) {
            var url = '@Url.Action("GetPortfolioOrigMarketValue", "Portfolio")';

            var dataVals = {};
            dataVals["id"] = "@Model.PortfolioID";
            dataVals["dsid"] = dsDropDownLst.value();
            dataVals["mvdate"] = dtMarketValue.value();

            $.ajax({
                type: "POST",
                url: url,
                data: JSON.stringify(dataVals),
                cache: false,
                contentType: 'application/json; charset=utf-8',
                success: function (resp) {
                    $(".setOrigVal").val(resp.OriginalValue);
                },
                dataType: 'json',
            });
        } else {
            $(".setOrigVal").val("");
        }

        calcVariance();
    }

Open in new window

0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 40590599
Two things.

1) Can you post the Action that your ajax is calling, so i can see how you are formatting the response?
2) Is it definitely calling the action? I notice the else clause in your script is explicitly setting the value to blank.
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question