View Full Version : How do I set focus using a variable?

01-01-2007, 12:39 AM
Hello -
I am new to javascript so all apologies -

Goal - to set focus to a form element when loading an asp page - using a variable (form name) passed when posting a form.

Detail - I have an asp page with a large number of forms wrapped in a div tag with overflow scroll. The user chooses to submit from any one of the forms and then variables (including the unique form name) are posted back to the server and the same page is reloaded. When the page reloads I would like the focus to be set back to the form that the user submitted from.

I am getting the setfocus to work if I hard code one of the form names (ex. "ab142") and call the function onload:

<script language=javascript>

function setFocus() {

// -->

(thumby is a text field name common to each form)

However, I haven't been able to figure out how to include the form name variable (focform) in the document.forms element.

I have set the variable name as follows:

<%set focusform = request.form("graphicname")%>

<script language=javascript>
var focform = '<%=focusform%>';

Can anyone help me with the code that would create the focus statement using the passed form name variable value?

Thanks very much!


01-01-2007, 02:38 AM



01-01-2007, 06:42 PM
It works!

Thanks again!!!