在JavaScript中使用If语句

时间:2015-02-05 18:52:18

标签: javascript jquery html parse-platform

我决定将以下内容添加到JavaScript

  if (form.address == "Vancouver, BC") {
      user.set("address", "#complete address");
} else if (form.address == "Edmonton, AB") {
      user.set("address", "complete address");
} else if (form.address == "Vancouver + United States") {
      user.set("address", "#complete address And 1300 Boblett Street, US");
} else if (form.address == "Edmonton + United States") {
      user.set("address", "complete address");
} 

并在控制台上收到以下错误:

TypeError: object is not a function

以下是整个代码

 $scope.signUp = function(form) {
    var user = new Parse.User();
    user.set("password", form.password);
        user.set("username", form.username);
                user.set("fullName", form.fname);

      user.set("companyName", form.cname);
      if (form.address == "Vancouver, BC") {
      user.set("address", "#1001 - 610 Granville Street Vancouver, BC V6C 3J3");
} else if (form.address == "Edmonton, AB") {
      user.set("address", "10915 65th Ave NW Edmonton, AB T6H 1W1");
} else if (form.address == "Vancouver + United States") {
      user.set("address", "#1001 - 610 Granville Street Vancouver, BC V6C 3J3 And 1300 Boblett Street, Unit-B1569 Blaine, WA 98230");
} else if (form.address == "Edmonton + United States") {
      user.set("address", "10915 65th Ave NW Edmonton, AB T6H 1W1 And 1300 Boblett Street, Unit-B1569 Blaine, WA 98230");
} 

           user.set("phoneNumber", form.pnumber);
          user.set("mailingAddress", form.maddress);
          user.set("plan", form.plan);


    user.signUp(null, {
      success: function(user) {
  window.location = 'payment.php'
      },
      error: function(user, error) {
      var div = document.getElementById("signUpError");
    div.textContent = "Unable to sign up: " + error.message;
     scroll(0,0);
      }
    });    
  };

基本上有一个表单,并且在其中有一个选项输入来选择一个地址,当某些例如选择new york时,它将存储解析该位置的完整地址(用户只看到纽约,但是后端存储完整的地址)。

1 个答案:

答案 0 :(得分:2)

当您看到此类型错误时,您将某些内容称为未定义为函数的函数。 例如:

var user = {
set: {
        phone: '',
        address:''
    }
};
user.set("phoneNumber", "form.pnumber");