Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Cannot assign to a function result

Posted on 2011-03-17
3
Medium Priority
?
684 Views
Last Modified: 2012-05-11
function Save()
  {
      if (EmployeeDetailsValidation())
      {
          $.ajax(
              {
                  type: "POST",
                  url: "Registration.aspx/Save",
                  data: "{'firstName': '" + $("#txtFirstName").val() + "','middleName': '" + $("#txtMiddleName").val() + "','lastName': '" + $("#txtLastName").val() + "','genderId': '" + $("#ddlGender").val() + "','divisionId': '" + $("#ddlDivision").val() + "','positionId': '" + $("#ddlPosition").val() + "'}",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: function ()
                  {
                    ClearEmployeeDetails();
                  },
                  error: function ()
                   {
                      alert("error");
                  }
              });
          }

      return false;
  }

function EmployeeDetailsValidation() {
      var isValid = false;

      if ($("#txtFirstName").val() != '' && $("#txtLastName").val() != '' && $("#ddlGender").get(0).selectedIndex != 0 &&
         $("#ddlDivision").get(0).selectedIndex != 0 && $("#ddlPosition").get(0).selectedIndex != 0) {

          isValid = true;
         }

      return isValid;
  }

function ClearEmployeeDetails()
  {
      $("#txtFirstName").val() = '';
      $("#txtMiddleName").val() = '';
      $("#txtLastName").val() = '';
      $("#ddlGender").get(0).selectedIndex = 0;
      $("#ddlDivision").get(0).selectedIndex = 0;
      $("#ddlPosition").get(0).selectedIndex = 0;
      $("#ddlPosition").attr("disabled", "disabled");
  }

 [WebMethod]
        public static void Save(string firstName, string middleName, string lastName, string genderId,
            string divisionId, string positionId)
        {
            try
            {
                Model.Employee employeeDetails = new Model.Employee();

                employeeDetails.EmployeeId = Guid.NewGuid();
                employeeDetails.FirstName = firstName;
                employeeDetails.MiddleName = middleName;
                employeeDetails.LastName = lastName;
                employeeDetails.GenderId = new Guid(genderId);
                employeeDetails.DivisionId = new Guid(divisionId);
                employeeDetails.PositionId = new Guid(positionId);

                Model.EmployeeRegistrationDC.Ins.Save(employeeDetails);
            }
            catch (Exception ex)
            {
               
                throw ex;
            }
        }

How to call  a function in a sucess function();

In success function, I am calling a  function "ClearEmployeeDetails() "
 to clear  the values, but I am getting javascript exeception "Cannot assign to a function result".

what is wrong in it and how to call a function in success function()

Is't possible to pass object  or  collection object in a query string to the page method, instead of passing values

data: "{'firstName': '" + $("#txtFirstName").val() + "','middleName': '" + $("#txtMiddleName").val() + "','lastName': '" + $("#txtLastName").val() + "','genderId': '" + $("#ddlGender").val() + "','divisionId': '" + $("#ddlDivision").val() + "','positionId': '" + $("#ddlPosition").val() + "'}",

Here I want to pass object or collection object.If we pass the object , how to convert the object to the custom object type(i.e. which we define as a parameter in pagemethod).

How to collection the data in the form of object or collection object in jQuery and how to pass it?

eg; {webMethod]
Public Static Void Save(Employee obj)
{
}

{webMethod]
Public Static Void Save(List<Employee> obj)
{
}

0
Comment
Question by:kravindra
[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
3 Comments
 
LVL 16

Expert Comment

by:Steve Krile
ID: 35156897
Just for the sake of clarity, could you post the html for these functions?  Just the form elements should be enough.
0
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 2000 total points
ID: 35157094
In order to clear a textbox use val("");
$("#txtFirstName").val('');

Open in new window

0
 
LVL 82

Expert Comment

by:hielo
ID: 35158740
>>How to call  a function in a sucess function();
The way you are calling it is correct

>>"Cannot assign to a function result"
These:
  $("#txtFirstName").val() = '';
  $("#txtMiddleName").val() = '';
  $("#txtLastName").val() = '';

should be:


  $("#txtFirstName").val("")';
  $("#txtMiddleName").val("")';
  $("#txtLastName").val("")';

OR:

  $("#txtFirstName").get(0).value = '';
  $("#txtMiddleName").get(0).value = '';
  $("#txtLastName").get(0).value = '';
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

604 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