/    Sign up×
Community /Pin to ProfileBookmark

methods and properties

can someone explain to me how I am to write a JS that uses methods calls rather than function calls. I am trying to write a script that uses an array of data and I want to display it according to one of several buttons a user presses.

what I mean is… if a user presses button A, the script will display all of the records. if the user presses button B, the script will display records in a range, if C — by a certain refernce, like a name in the record, etc etc

I dont know if I am clear in my description.

I need functions, for sure, but I need to write a new function to support each button. Each function supports a method like this to define a new method (inside the constructor function):

this.toString = hlToString;

The name of the method is ‘toString’. ‘hlToString’ is the name of the function.

I am trying to make a form where users click certain buttons to get results to display in the text area depending on clicks.

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@psuedocodeauthorMar 17.2005 — attached is a textfile of what I have so far...

in it, I have some confusion about why this line isnt returning valid object...

<input type="button" value="Show All Listings" onClick="showListings();">

it calls the function showListings, which uses the method toString (defined in the HomeListing function-- this.toString = hlToString)

<i>
</i>function HomeListing( number, price, homeSF, lotSF, agent )
{
// constructor for the HomeListing object

// PROPERTIES
this.listingNumber = number;
this.listPrice = price;
this.homeSqFt = homeSF;
this.lotSqFt = lotSF;
this.agentName = agent;

// METHODS
this.getCostPerSqFt = hlGetCostPerSF;
this.toString = hlToString;
}
Copy linkTweet thisAlerts:
@psuedocodeauthorMar 17.2005 — [i]Originally posted by psuedocode [/i]

[B]attached is a textfile of what I have so far...

[/B]
[/QUOTE]
I dont know why it didnt attach the file... but I will try again....

[upl-file uuid=87189e2b-559b-42b7-813a-4e0ccb6249dc size=3kB]real.txt[/upl-file]
Copy linkTweet thisAlerts:
@MongusMar 17.2005 — Just a quick look shows that you're trying to set the value of a field named "out" in the "rays" form. The problem is there is no "out" field. Maybe you meant "mls"?

There may still be more problems. I didn't check further.
Copy linkTweet thisAlerts:
@psuedocodeauthorMar 17.2005 — ummm, *cough* yea... that would make sense....


geez. thanks Mongus
Copy linkTweet thisAlerts:
@MongusMar 18.2005 — No problem. JavaScript error messages are your friends. ?
Copy linkTweet thisAlerts:
@psuedocodeauthorMar 18.2005 — trying to get the other buttons to work, I have this function written, but it says it is not an object.

<i>
</i>function showHighestCostSqFt()
{
document.rays.mls.value="";
var indexOfHighest = 0;
for( i = 1; i &lt; listings.length; i++ )
if ( listings[i].homeSF &gt; listings[indexOfHighest].homeSF )
indexOfHighest = i;
document.rays.mls.value += listings[i].toString( );
}


should I be putting some other variable in other than 'listings' ?
Copy linkTweet thisAlerts:
@MongusMar 18.2005 — Sounds like it's complaining about "i" because it's out of scope when you use it. You're either missing brackets or your last line should use indexOfHighest instead of i depending on what you're trying to do.
×

Success!

Help @psuedocode spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...