hi all,

I want to call a class function using beans inside java script. but it is not working. It calls that function only 1 time.

<jsp:useBean id="track" scope="session" class="ReturnProgress"></jsp:useBean>

<script type="text/javascript">
function getProgress()
{
document.getElementById('progress').innerHTML = '<%=track.findProgress()%>';
}


</script>

I want that Whenever user clicks on button , I call getProgress function on onclick event that fetches progress using findprogress() method.
please help.

you probably need to supply some more information. you say it only calls the method once, but are you sure this is the result of your onclick event? if it is infact calling it from the onclick, then each click should call it again, and maybe your output is not actually changing? this would then indicate a issue with your java, and not the java script.

good luck

Thanks for reply.
You are right. It gets called when page loads.
Then after each time you click it keeps on displaying same information i.e. it does nt call function.
So how can i make sure that this function does not get called when page loads but on button click.

can you post your html (w/ javascript)?

EDIT: it should just be something like:

onclick="getProgress()"
<html>
<head>
<jsp:useBean id="track" scope="session" class="ReturnProgress"></jsp:useBean>


<script type="text/javascript">
function getProgress()
{
document.getElementById('error')='<%=track.findProgress()%>';
}
</script>
</head>
<body>

<p id = "error"> </p>
<button onclick = "getProgress()">click me</button>
</body>
</html>

Is it correct to call this function like this beacuse this function runs on server side.

Hi,

Did you ever resolve this?

I would like to call a set method in a bean using a value that
I extract from getElementById. I can get the value OK and usually
I send these back to my page and access them as request parameters.

I am trying to avoid having to resend the page of course.
i tried this but the JavaScript failed with an error:

clientBean.setClientId(selectedClient.value);

clientBean is a session bean created with a usebean tag.
setClientId is a set method in an entity bean I created.
selectedClient.value is the value I want to pass as an argument.

the Javascript is below:

<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>ExpenseEntryGet JSP Page</title>
        <link rel="stylesheet" href="css/CascadeMenu.css"/>
        <script type="text/javascript" src="scripts/CascadeMenu.js">
        </script>  
        <script language="java", type="text/javascript">
        function SetSelectedClientID()
            {
             var clients = document.getElementById('clientSel');   
             var selectedClient = clients.options[clients.selectedIndex];
             clientBean.setClientId(selectedClient.value); 
            }

Any idea as to how to access my set method via the usebean this way?
It is the opposite of what you want to do seemingly which is bean value
to tag element value.

Thanks,
Brian

hi all,

I want to call a class function using beans inside java script. but it is not working. It calls that function only 1 time.

<jsp:useBean id="track" scope="session" class="ReturnProgress"></jsp:useBean>

<script type="text/javascript">
function getProgress()
{
document.getElementById('progress').innerHTML = '<%=track.findProgress()%>';
}


</script>

I want that Whenever user clicks on button , I call getProgress function on onclick event that fetches progress using findprogress() method.
please help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.