/    Sign up×
Community /Pin to ProfileBookmark

problem of ‘jsp’ code in javascript function

How can i add ‘javascript’ variable in javascript function with ‘jsp’ variable
example:

function s(){
var count=1;
<%
int i=0;
i(‘jsp’ variable)+count(‘javascript’ variable)
%>
}

My next problem specification is in my bellow code.In this code i want to execute a ‘jsp’ loop instead of ‘javascript’ loop.please help me quickly.

/////////////////code//////////////
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
</head>
<%
String n=”shanto”;
String n1=”bos”;
%>
<body>
<form name=”form1″ >
<p>
<select name=”select1″ onChange=”change()”>
<option value=”12″>hi</option>
<option value=”12″>i</option>
</select>
</p>
<p>
<select name=”select2″>

</select>

</p>
</form>
</body>
</html>

<script language=”JavaScript”>

var count=1;
function change(){

///////////////// Problem /////////////
for(var i=0;i<3;i++){//here i want to execute ‘jsp’ loop instead of ‘javascript’ loop//

if(count%2==0)
document.form1.select2.options[i]=new Option(“<%=n1%>”,”<%=n%>”,false,false);
else
document.form1.select2.options[i]=new Option(“<%=n%>”,”<%=n%>”,false,false);

}
count++;

}

</script>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisAug 15.2006 — You can't mix JSP and JAVASCRIPT. JSP runs on server, while JAVASCRIPT runs on client.
Copy linkTweet thisAlerts:
@ahk2chanAug 15.2006 — That means before the Javascript get run on the client's browser, the JSP has already been executed on the server side, so:

  • 1. when the JSP execute, it still doesn't know the value of the javascript variable yet.


  • 2. Your JSP loop will already be executed on the server side.
  • ×

    Success!

    Help @shanto spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...