Hello,
I would like to use a button as a link and pass the session variable in a jsp!
The below code should work.
Any help is appreciated.
Thanks.

I use encodeURL if the user has cookies off.
This works with links but not when using an input button with window.location.href.

<input type="button" value="Copy" onClick="window.location.href='<%= response.encodeURL("http://www.mysite/index.jsp?switch="+ intvariable) %>'">

Recommended Answers

Your quoting seems to be off. Try something like:

<script type="text/javascript">
function redirectUser() {
  var url = '<%= response.encodeURL("http://www.mysite/index.jsp?switch="+ intvariable) %>';
  window.location.href = url;
}
</script>

<!-- more code -->
<input type="button" value="Copy" onclick="redirectUser();">
Jump to Post

All 2 Replies

Your quoting seems to be off. Try something like:

<script type="text/javascript">
function redirectUser() {
  var url = '<%= response.encodeURL("http://www.mysite/index.jsp?switch="+ intvariable) %>';
  window.location.href = url;
}
</script>

<!-- more code -->
<input type="button" value="Copy" onclick="redirectUser();">
Be a part of the DaniWeb community

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