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 8377573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:42:19+00:00 2026-06-09T15:42:19+00:00

I’ve got a custom class in Javascript called Booking: function Booking(technicianID, startTime, start, street,

  • 0

I’ve got a custom class in Javascript called Booking:

function Booking(technicianID, startTime, start, street, zipcode, jobtypeID) {
    this.technicianID = technicianID;
    this.startTime = startTime;
    this.start = start;
    this.street = street;
    this.zipcode = zipcode;
    this.jobtypeID = jobtypeID;
}

I want to use an object of this class as input in a function.

function bookTime(inputBooking) {
    var tmpBooking = inputBooking;
    alert("You chose: " + tmpBooking.start + ". Tech: " + tmpBooking.technicianID);
}

But for some reason all I get from the alert is “undefined” for the variables. I guess it’s because it doesn’t see inputBooking as a Booking object, which means it doesn’t have the variables start and technicianID…

I read that there is a Object.create function you can use, but I can’t get it to work.

    tmpBooking = Object.create(Booking, inputBooking); 

Any ideas on how to solve this?

EDIT:

If I send in the inputBooking object from javascript directly it works as expected.

    var tmpBooking = new Booking(tmpTechID, tmpStartTime, tmpStart, tmpStreet, tmpZipcode, tmpJobtypeID);

    bookTime(tmpBooking);
    //Works

But the problem is that I want to send a temp object to HTML and generate a button that will call the bookTime function:

    var tmpBooking = new Booking(tmpTechID, tmpStartTime, tmpStart, tmpStreet, tmpZipcode, tmpJobtypeID);

    resultsHTML += "<a href=\"#\" onclick=\"bookTime('" + tmpBooking + "')\">Book!</a>";
    //Doesn't work

When I run this with debugger it says that inputBooking is of type [object Object] and “Children could not be evaluated”.. The result is that start and technicianID variables are undefined.

  • 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-09T15:42:20+00:00Added an answer on June 9, 2026 at 3:42 pm

    There is nothing wrong in the code that you show. If you call the function with an actual Booking object, it works as expected:

    bookTime(new Booking('Tech1', 'Now', 'Now', 'Here', 'Zip', 'Job'));
    

    Demo: http://jsfiddle.net/Guffa/fRmA2/

    So, your problem is most likely that it’s not a Booking object that you send into the function.

    Edit:

    You are creating HTML code that contains the string representation of the object, but the string representation of the object can’t be used to recreate an object that looks the same.

    Either use the variable in the code:

    resultsHTML += "<a href=\"#\" onclick=\"bookTime(tmpBooking)\">Book!</a>";
    

    or create code that will create an object:

    resultsHTML += "<a href=\"#\" onclick=\"bookTime(new Booking(tmpTechID, tmpStartTime, tmpStart, tmpStreet, tmpZipcode, tmpJobtypeID))\">Book!</a>";
    

    However, depending on where you get the data from, or whether you are using it in a loop, neither of those may work. If the variables that you use are not available globally, you would need to use the values of each variable to create code that creates the object. Something like:

    resultsHTML += "<a href=\"#\" onclick=\"bookTime(new Booking('"+tmpTechID.replace(/\\/g,'\\\\').replace(/'/g,'\\'')+", '"+tmpStartTime.replace(/\\/g,'\\\\').replace(/'/g,'\\'')+", '"+tmpStart.replace(/\\/g,'\\\\').replace(/'/g,'\\'')+", '"+tmpStreet.replace(/\\/g,'\\\\').replace(/'/g,'\\'')+", '"+tmpZipcode.replace(/\\/g,'\\\\').replace(/'/g,'\\'')+", '"+tmpJobtypeID.replace(/\\/g,'\\\\').replace(/'/g,'\\'')+"))\">Book!</a>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
Specifically, suppose I start with the string string =hello \'i am \' me And
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.