title: how to pass a string to a javascript function in xhtml?
body: <pre><code>function passString(str)
  {
      alert(str);
  }
  
  function passText()
  {
      str = document.getElementById('formId:hidden1').value;
      alert(str);
  }
  </code></pre>
  
  <p>I am using both of the above javascript functions to get the string obtained from a jsf bean file but none is working. The string is successfully obtained from the "#{addRoute5.teamNames}"(jsf bean File - see below) and displayed in the inputText, but the javascript cant accept string for some reason from xthml. My code in xhtml file is as follows:</p>
  
  <p>Thanks in advance</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"&gt;
      &lt;f:view&gt;
          &lt;h:head&gt;
              &lt;link href="css/myCss1.css" rel="stylesheet" type="text/css"/&gt;
              &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no" /&gt;
              &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"/&gt;
              &lt;title&gt;Paris-Dakar Rally&lt;/title&gt;
              &lt;link href="css/mapsStyle.css" rel="stylesheet" type="text/css"/&gt;
              &lt;script type="text/javascript" src="//maps.googleapis.com/maps/api/js?    sensor=false"&gt;&lt;/script&gt;
  
          &lt;/h:head&gt;
          &lt;h:body onload ="#{addRoute5.calculateLatMarker()}"&gt;
              &lt;div id="container"&gt;
                  &lt;div id="header"&gt;
                      &lt;div id="title"&gt;
                          &lt;span&gt;Paris - Dakar Rally&lt;/span&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  
                  &lt;div id="map_canvas"&gt;&lt;/div&gt;
  
                  &lt;h:form id="formId"&gt;
  
  
                      &lt;div id="body"&gt;
  
                          &lt;div class="transbox"&gt;
                              &lt;h:inputText id="hidden1" value="#{addRoute5.teamNames}"/&gt;                            
                              **&lt;h:commandButton type ="button" value="Start Simulation"     onclick ="passText()" or onclick="passString(#{addRoute5.teamNames})"/&gt;**
  
  
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;/h:form&gt;
              &lt;/div&gt;
          &lt;/h:body&gt;
      &lt;/f:view&gt;
  &lt;/html&gt;
  </code></pre>