Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9244931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:09:01+00:00 2026-06-18T09:09:01+00:00

Hello I am messing with an object in Javascript. Here is my object in

  • 0

Hello I am messing with an object in Javascript. Here is my object in a seperate .js file.

json-webservice.js

      //create object
function objdata(tool, product, details) {


    //create object properties
    this.tool = tool;
    this.product = product;
    this.details = details;


    //create object methods
    this.validate = function () {
        var error = 0;
        for (var prop in this) {

            if (this.hasOwnProperty(prop)) {
                if (prop != 'validate' || prop != 'submit') {
                    if (this[prop] == null || this[prop] == undefined || this[prop] == "") {
                        error += 1;
                    }
                }

            }
        }

        return error;
    }

    this.submit = function () {

        var error = this.validate();

        if (error > 0) {
            alert("errors: " + error);
        }
        else {
            alert(this.tool + " " + this.product + " " + this.details);
        }
    }

}


}

I include this script in the head of my page index-main.html.

Then document ready, and then initialize the new object and submit.

$(document).ready(function () {

    var userdata = new objdata('5', 'Main Page', '9');
    userdata.submit();

});

My question is why does it only alert

---------------------------
Windows Internet Explorer
---------------------------
5
---------------------------
OK   
---------------------------

and not

---------------------------
Windows Internet Explorer
---------------------------
5 Main Page 9
---------------------------
OK   
---------------------------

like I think it should. Is my object correctly coded? I didn’t have any javascript errors reported in IE.

The wierd part is I can copy the json-webservice.js file contents (the object above) and it works perfectly. It does not work as an external file though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:09:02+00:00Added an answer on June 18, 2026 at 9:09 am

    You need to use this[prop] rather than this.prop; the former looks for a property whose name is the string in prop, while the latter looks for a property whose name is literally “prop.”

    (I couldn’t get it to reproduce the output you had. As written, it was just alerting “error”, and the change above caused it to give the desired output.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are many JavaScript functions out there that accept an object directly here are
Hello all I am working on javascript jquery and svg.I want to ask a
Hello all I am working on html and javascript.And I am going to ask
Hello ! I need to create a report like the attachment shows with Jasper
Trying to grasp Prototyping in Javascript. Trying to create my own namespace to extend
I get the following error: Error 1 error C3867: 'CHelloproxy::Hello': function call missing argument
gcc 4.7.2 Hello, I am trying to create a shared library that uses the
With equals sign: object HelloWorld { def main(args: Array[String]) = { println(Hello!) } }
Hello people of Stackoverflow! I have been going through the Mozilla Developer Network's JavaScript
In the code presented here: Gant file , there is the following code: target(dist:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.