troubleshooting Question

JavaScript function with arguments 131122

Avatar of Allen Pitts
Allen PittsFlag for United States of America asked on
JavaScript
5 Comments2 Solutions307 ViewsLast Modified:
Hello Expert.

JavaScript in HTML page below passes argument from onClick event to function
Hospital _Name to display the name and aliases.


1. Would like to stack the aliases in the alert by putting a page break in the alert like
alert("The Hospital Name is " + name + ".  The aliases are " + alias1 + ",<br />  " + alias2 + "<br />, " + alias3 + "<br />, " + alias4);

But this does not cause a page break but just displays the  string <br />.
How can I begin a new line with each of the alias names?

2. Right now in the function calls by onClick where the last parameter is empty quotes  
a comma appears after the last alias. So I tried taking the comma out but that made the button disappear. How can I get rid of the comma after the last parameter with a string?

Thanks.

Allen in Dallas


<!DOCTYPE html>
<html>
<title>LHP Hopsital Group</title>

<style type="text/css">
 body {font-family: arial;}
 </style>

<body>

<p>Click one of the buttons to call see the the hospital alaises</p>

<button onclick="Hospital_Name('Portneuf Medical Center','PMC','Portneuf','Pocatello','_')">Portneuf Medical Center</button><br />
<button onclick="Hospital_Name('Texas Health Presbyterian Hospital-WNJ','Wilson-Jones' , 'THR-WNJ', 'PWNJ', 'Sherman')">Texas Health Presbyterian Hospital-WNJ</button><br />
<button onclick="Hospital_Name('Seton Medical Center Harker Heights','HH', 'SMCHH', 'Killeen', 'Seton')">Seton Medical Center Harker Heights</button><br />
<button onclick="Hospital_Name('Bay Medical Center Sacred Heart Health System','BMC', 'Panama City', 'Sacred Heart', '')">Bay Medical Center Sacred Heart Health System</button> <br />
<button onclick="Hospital_Name('HackensackUMC Mountainside','HUMC', 'MSH', 'Montclair', '')">Hackensack UMC Mountainside</button> <br />
<button onclick="Hospital_Name('Hackensack University Medical Group','HUMC-PV', 'Pasack Valley', 'Westwood', '')">Hackensack University Medical Group</button> <br />
<br />
<br />

<script>
function Hospital_Name(name,alias1,alias2,alias3,alias4)
{
alert("The Hospital Name is " + name + ".  The aliases are " + alias1 + ",  " + alias2 + ", " + alias3 + ", " + alias4);
}
</script>

This page has a function called hospitalName which is declared with five placemaker arguments,<br />
'name', 'alias1', 'alias2', 'alias3', and 'alias4'. When button calls the function there are five arguments,<br />
passed to the function depending on which hospital is called <br />
by the onClick event associated with the button.<br />
These five strings replace the placemaker <br />
arguments used to create the function with string values that are  <br />
passed to function when then button is clicked<br />

</body>
</html>
ASKER CERTIFIED SOLUTION
VincentPuglia

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros