Javascript Code - Line by Line, How Does This Work?

I'm working on someone else's project and I know just enough about JavaScript to be frustrated...

Here's the code that exists as well as my "explanation" as to what's going on. If I could have someone fill in the gaps and correct me where I'm wrong, I would appreciate it.

<span onmouseover="'underline';"
onmouseout="'none'" //like a link, user sees the "add physician" text underlined when the mouse over it

onclick='loadlookup  //going to call a function when the user clicks on the "add physician" text

(dataform,"physician_lookup",entityid,physicianid,physician,"physician")'>add physician</span>//here's where I'm getting a little fuzzy. Looks like several variables that are getting ready to be passed into a form to be evaluated in some way

&nbsp;&middot;&nbsp;<span class='clickableLite' onmouseover="'underline';"
onclick='clearfield(dataform,"physicianid","physician",physicianname,"physician")'>clear all</span>//same kind of thing as above.

Open in new window

Now here's the loadlookup function being called...

function loadlookup(form, page, entityid, id, name, label) {// here are the variables that this function is going to be evaluating

	lookuplabel.innerHTML = '<span class=\'legend\'>Click name to add:</span>  '+label; // it looks as though that when the user clicks on the above link, part of the task that the activated function is going to be doing includes the assertion of a line of text, which in this case is, "Click name to add:"

	lookupentity = form.entityid.value; /I'm thinking this is the dynamic that defines the "label" variable referenced above, but where is "form.entityid.value" coming from?

	switch (label) {
		case "physician" :
			groupid = form.specialtyid.value;
		case "payer" :
			groupid = form.finclassid.value;
		default :
			groupid = "";

Open in new window

If someone could confirm and / or correct what I've got above in terms of comments and then add whatever else I may be missing, I would appreciate it.
brucegustPHP DeveloperAsked:
Who is Participating?
Julian HansenConnect With a Mentor Commented:
To answer (literally) the code takes as input 5 parameters of which we can guess that from refers to a form on the page and the rest is a bit more vague.

Line 2
Sets the html content of the lookuplabel - although it is not possible to tell where lookuplabel comes from or where it is defined or why it is being set as it is.

Line 3
sets lookupentity to the value of the entityid field on the form (example<input> element)

Line 4
Starts a switch statement based on the label parameter. From the posting there appear to be 2 possibilities - physician and payer

In the case of physician the groupid variable (unclear as to where it is defined or how it is used) is assigned the value of the from element specialityid.

In the case of payer groupid is assigned the value of the form element finclassid.

In answer to your question in your comment
where is "form.entityid.value" coming from
The answer is entityid is a form element with an id of entityid.

That is all we can tell from what you have posted.
This would be easier if you just posted the full elements HTML and the full js functions, instead of bits of everything that just makes it look like a mess.
brucegustPHP DeveloperAuthor Commented:
Yeah, it would. But all I've got is screen shots. I can upload those if you like, but I don't have the actual HTML code.
brucegustPHP DeveloperAuthor Commented:
Julian, that gives me what I need at this point.

Julian HansenCommented:
You are welcome - thanks for the points.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.