Solved

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

Posted on 2014-02-24
5
215 Views
Last Modified: 2014-02-24
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="this.style.textDecoration='underline';"
onmouseout="this.style.textDecoration='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="this.style.textDecoration='underline';"
onmouseout="this.style.textDecoration='none';"
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;
			break;
		case "payer" :
			groupid = form.finclassid.value;
			break;
		default :
			groupid = "";
			break;
		}

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.
0
Comment
Question by:brucegust
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39883723
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.
0
 
LVL 58

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39883897
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.
0
 

Author Comment

by:brucegust
ID: 39883992
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.
0
 

Author Comment

by:brucegust
ID: 39883997
Julian, that gives me what I need at this point.

Thanks!
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 39884013
You are welcome - thanks for the points.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question