Solved

Cannot assign to a function result

Posted on 2011-03-17
3
635 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
3 Comments
 
LVL 16

Expert Comment

by:Steve Krile
Comment Utility
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 500 total points
Comment Utility
In order to clear a textbox use val("");
$("#txtFirstName").val('');

Open in new window

0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
>>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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Page not loading properly 15 38
Get value before .onChange() 5 25
Re-position sub-options beneath the TAB 7 36
jqplot Pie Chart 2 11
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now