title: Javascript: Passing parameters to a function to call a variable
body: <p>Having trouble at work when trying to enhance a function. I just took an introductory couse in Javascript so I'm hoping I will find a lot of people to help me get better. :)</p>
  
  <p>here is an example of what I want to do: </p>
  
  <pre><code> &lt;script type="text/javascript"&gt;
  
  var title1 = "&lt;h2&gt;Cisco&lt;/h2&gt;";
  var summary1 = "&lt;p&gt;Cool class&lt;/p&gt;";
  var Register1 = "&lt;button&gt;Register&lt;/button&gt;";
  
  var title2 = "&lt;h2&gt;Whatever title&lt;/h2&gt;";
  var summary2 = "&lt;p&gt;Whatever Summary&lt;/p&gt;";
  var Register2 = "&lt;button&gt;Whatever Register&lt;/button&gt;";
  
   //But I have to create about 10 functions if I do it this way...
       function course1()
       {
            document.getElementById('courseTitle').innerHTML = title1;
            document.getElementById('courseSummary').innerHTML = summary1;
            document.getElementById('courseRegister').innerHTML = Register1;
  
       }
  
       function course2()
       {
            document.getElementById('courseTitle').innerHTML = title2;
            document.getElementById('courseSummary').innerHTML = summary2;
            document.getElementById('courseRegister').innerHTML = Register2;
  
       }
  
  //So I taught about doing it with parameters so I could only build one function. 
  //For some reason it doesn't work.
  
  
  //Here is how my improved function idea looks
       function course(x)
       {
            document.getElementById('courseTitle').innerHTML = title+x;
            document.getElementById('courseSummary').innerHTML = summary+x;
            document.getElementById('courseRegister').innerHTML = Register+x;
  
       }
  
  //And here is how you would call them
  
  &lt;input type"button" value="course1" onclick="course(1)"&gt;
  &lt;input type"button" value="course1" onclick="course(2)"&gt;
  </code></pre>
  
  <p></p>
  
  <p>I would appreciate any help! Thank You.</p>