Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to do a Setfocus in ASP page 1

Status
Not open for further replies.

rap43

Programmer
Apr 21, 2003
13
US
I have a HTML form within a ASP page that after the user enteres data in a textbox and the asp does it's display of selected items I want the cursor to go back to the textbox entry area.

I know that VBScript does not have a Setfocus, is there another way of doing this?

Thanks.
 
Javascript.

<body onLoad=&quot;document.formname.inputname.focus()&quot;>
 
VBScript does have SetFocus, but you can use object.Focus in place of this just like you can in JavaScript.
 
JavaScript is better to use for that if you run your script on you public website. It is compatible with more different browsers than the VB method. Just name your form and form elements and then put it in its place as you saw upper there it will work fine.
 
VBScript does have SetFocus

But ASP does not have this capability. baddos has the only solution to the question pertaining to ASP

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811[/sub]
onpnt2.gif
 
form(login)
???

what do you mean lebisol? I went to the link and there is no default focus set

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811[/sub]
onpnt2.gif
 
Add this in your <script> tag before the functions.

document.Login.tfUserName.focus()
 
ONPNT:
the only form on the page......on the left side &quot;username&quot; and &quot;password&quot; fields are set onFocus?! is this what u need?
:(
 
but they're not lebisol. That's all I was saying.
I wen to the link in NN6+ and IE5+ and the focus is not on the form in anyway.

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811[/sub]
onpnt2.gif
 
hm? that is weird...IE 5.5 w2k and its all good for me?! :(
---------snip-----------
<input name=&quot;tfUserName&quot; type=&quot;text&quot; onFocus=&quot;if(this.value=='User')this.value='';&quot; value=&quot;User&quot; size=&quot;9&quot;>

<input name=&quot;tfPassword&quot; type=&quot;password&quot; onFocus=&quot;if(this.value=='Password')this.value='';&quot; value=&quot;Password&quot; size=&quot;9&quot;>
-----------snap---------

with the defaults of:
User: [Username]
Password: [******]
....I don't what to say...I though it was working but I guess not! :)

 
OOOOooooo!!

I see where I'm getting a bit confused here. [lol] (onpnt?!? confused!!)

you're not actually setting focus. you're setting a default value and &quot;on&quot; focus you're cahnging the values. A way for you to actually set the focus to the first text would be a onLoad=&quot;formfield.focus()&quot;

That's what I was trying to see. sorry for the confusion. :)

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811[/sub]
onpnt2.gif
 
onpnt:
no problem....well, we (at least) posted enought for others to learn from the confustion :)
All the best
 
[lol] no doubt lebisol

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811[/sub]
onpnt2.gif
 
Ok - I tried it Onpnt and not working. Here is the HTML form code below. Where would your onload.setfocus go?

<Form action=&quot;sample1.asp&quot; method=&quot;get&quot;>
Search String: <input type=&quot;text&quot; name=&quot;searchstr&quot; size=&quot;20&quot;>
<input type=&quot;submit&quot; value=&quot;Submit&quot;>
<input type=&quot;hidden&quot; name=&quot;issubmitted&quot; value=&quot;YES&quot;>
</Form>
 
umm.. tried what?

anyhow, the onLoad event goes in the body tag.
eg:
<body onLoad=&quot;document.forms[0].searchstr.focus()&quot;>
<Form action=&quot;sample1.asp&quot; method=&quot;get&quot;>
Search String: <input type=&quot;text&quot; name=&quot;searchstr&quot; size=&quot;20&quot;>
<input type=&quot;submit&quot; value=&quot;Submit&quot;>
<input type=&quot;hidden&quot; name=&quot;issubmitted&quot; value=&quot;YES&quot;>
</Form>

notice the use of document.forms[0]
this is due to no name in the form tag.

on that note if you need further assistance you may want to refer to the javascript forum. forum216

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811[/sub]
onpnt2.gif
 
just realized baddos already said the same thing I did also. credit goes the baddos on this one.

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811[/sub]
onpnt2.gif
 

I am not good at JS but....something like this...

<script>
function FUNCTION_NAME ()
{
document.FORM_NAME.form_field_name.focus()
}
</script>
<body onLoad=&quot;FUNCTION_NAME ();&quot;>

:|
all the best!

 
OnPnt - You are to be worshipped. [thumbsup2]

<body onLoad=&quot;document.forms[0].searchstr.focus()&quot;>

Did the trick!! Thanks to you and all who replied.

 
Just want to give a star because I've been searching for 2 days to find the correct syntax in an asp page to get the focus to a textbox onLoad.
<body onLoad = &quot;document.forms[0].txtPersonRequesting.focus();&quot;>

worked for me.

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top