function passString(str)
{
alert(str);
}
function passText()
{
str = document.getElementById('formId:hidden1').value;
alert(str);
}
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:
Thanks in advance
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view>
<h:head>
<link href="css/myCss1.css" rel="stylesheet" type="text/css"/>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Paris-Dakar Rally</title>
<link href="css/mapsStyle.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="//maps.googleapis.com/maps/api/js? sensor=false"></script>
</h:head>
<h:body onload ="#{addRoute5.calculateLatMarker()}">
<div id="container">
<div id="header">
<div id="title">
<span>Paris - Dakar Rally</span>
</div>
</div>
<div id="map_canvas"></div>
<h:form id="formId">
<div id="body">
<div class="transbox">
<h:inputText id="hidden1" value="#{addRoute5.teamNames}"/>
**<h:commandButton type ="button" value="Start Simulation" onclick ="passText()" or onclick="passString(#{addRoute5.teamNames})"/>**
</div>
</div>
</h:form>
</div>
</h:body>
</f:view>
</html>
Stop. Step back. Break the problem down.
The code you have provided is a template that will be processed on the server. Then passed to a browser. Then the browser will extract the JavaScript from the HTML and run it.
Look at the source code the browser processes. Then ask yourself “Does this JavaScript not do what I expect? Or does the template not output the JavaScript I want?”
It looks like you have this:
which will generate something like:
when you want something like: