Forum Moderators: open

Message Too Old, No Replies

setFocus dynamically

Use parameter to dynmically setFocus

         

louis2

4:40 pm on Oct 25, 2004 (gmt 0)



I have a main JSP page that is forwarded to by other JSPs. This main JSP page has 4 named forms in it. I need to setFocus to one of these forms. Which form the focus should be set to depends on which JSP forwarded to it. How can I use JavaScript to dynamically setFocus using a parameter sent by the source JSP? I'm VERY NOVICE with JavaScript and novice with JSP.

Rambo Tribble

2:20 am on Oct 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't have much experience with JSP, but all server scripts seem to work in a similar fashion in this regard. What you will need to do is have the JSP script include the value you want in a variable declaration in the script portion of the output page. You can then use that variable in your client-side scripts.

BlobFisk

11:03 am on Oct 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about passing the variable through using JSP (and picking it up using javax.servlet.http.HttpServletRequest) and then using this variable to populate the form name in the JS:

<script type="text/javascript>
document.<%= FORM_NAME_VARIABLE %>.fieldName.focus();
</script>