?
Solved

Cannot assign to a function result

Posted on 2011-03-17
3
Medium Priority
?
672 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Suggested Courses

770 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