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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

focus on textbox

Status
Not open for further replies.

KryptoS

Programmer
Feb 7, 2001
240
BE
hello I have a problem with focus on a textbox. I have the following code in ASP

<form action=&quot;opslaan.asp&quot; method=&quot;post&quot; name=&quot;formtest&quot;>
<%
While (Not oRS9.EOF)
teller = teller + 1
Response.Write (&quot;<input type=text name=textfield&quot; & teller & &quot; value ='' size = 15 disabled>&quot;)
%>


now I want to get the focus on lets say: textfield2 (or whatever) I know it's something like:
document.formtest.textfield2.focus()

but this doesn't work, I think it's because I use name=textfield&quot;&teller ... can someone help me?
 
in the function that is supposed to focus on the textfield :
alert(documen.formtest) - is it undefined ? no ?
-> then
alert(documen.formtest.textfield2) - is it undefined ? no ?
-> then it's NOT because you use textfield&teller
-> yes it's undefined ? then do &quot;view source&quot; on the GENERATED page. What are the name of the fields (ie : what is written here : <input type=text name=...>) ?
-> document.formtest is undefined ? then check the name of the form ...

-> any thing else ? use the netscape console it's done to debug and very very helpful

let me know
but you should have precised WHAT is not working. I mean, as you can't focus a disabled field (as far as i know) maybe everything is fine and working normally
 
Look this is what my programme is about, I have textfields where I put some data in, after I changed the data in a field I go to a function to test if the data is numeric, if it isn't numeric I want the focus back on that field until it's correct ... now I did some test, and it works when I go to another field whithout using the tab-key. So the problem is when I use the tab-key, my programme looks if the data is correct (if not gives an alert), but then he goes to the next field ... I don't know why ... please help
 
thank you for you time and help, I call the function after a onChange on the textfield, then a validate the data in the textfield ...

thank you
 
with tab it doesn't always detect onchange
the very best way to validate any kind of form is :
---
1- set a validation function that will validate ALL of your fields, and, VERY important, let it return true or false. For example :
function check_no_field_is_empty(a_form){
if (a_form.textbox1.value!=&quot;&quot; && a_form.textbox2.value!=&quot;&quot; && a_form.selectbox.selectedIndex!=-1)
return true
else {
alert (&quot;please fill in all the fields&quot;)
return false
}
}
[&quot;;&quot; at the end of the lines are not important at all, but the return true or false ARE]
----
2- call it ONSUBMIT - onclick or onchange will give various result, often unexpected
<form name=&quot;&quot; action=&quot;&quot; target=&quot;&quot; method=&quot;&quot; onsubmit=&quot;javascript:return check_no_field_is_empty(this)&quot;>
----
this should solve your problem
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top