elements of a form

K

kirku

hello,
i'm not very good with english
i will explain my problem wit an exemple:
// i have a form called dati
var nome_var="email"; //for exemple
ex1=document.dati.elements[nome_var].value //it's ok, work right
document.dati.email.focus( ) //it's ok, work
right
document.dati.elements['email'].focus( ) //it's ok, work right
//but i need something like this:
document.dati.elements[nome_var].focus //IT IS NOT OK

how can i get focus to "emial" element of form dati, using a variable unitl
the 'name'.

thank you for help.
 
L

Lee

kirku said:
hello,
i'm not very good with english
i will explain my problem wit an exemple:
// i have a form called dati
var nome_var="email"; //for exemple
ex1=document.dati.elements[nome_var].value //it's ok, work right
document.dati.email.focus( ) //it's ok, work
right
document.dati.elements['email'].focus( ) //it's ok, work right
//but i need something like this:
document.dati.elements[nome_var].focus //IT IS NOT OK

how can i get focus to "emial" element of form dati, using a variable unitl
the 'name'.

document.dati.elements[nome_var].focus();
 
M

McKirahan

kirku said:
hello,
i'm not very good with english
i will explain my problem wit an exemple:
// i have a form called dati
var nome_var="email"; //for exemple
ex1=document.dati.elements[nome_var].value //it's ok, work right
document.dati.email.focus( ) //it's ok, work
right
document.dati.elements['email'].focus( ) //it's ok, work right
//but i need something like this:
document.dati.elements[nome_var].focus //IT IS NOT OK

how can i get focus to "emial" element of form dati, using a variable unitl
the 'name'.

thank you for help.


Try ".focus()".

Also, try "document.getElementById(nome_var).focus()".
 
K

kirku

Lee said:
kirku said:
hello,
i'm not very good with english
i will explain my problem wit an exemple:
// i have a form called dati
var nome_var="email"; //for exemple
ex1=document.dati.elements[nome_var].value //it's ok, work right
document.dati.email.focus( ) //it's ok, work
right
document.dati.elements['email'].focus( ) //it's ok, work right
//but i need something like this:
document.dati.elements[nome_var].focus //IT IS NOT OK

how can i get focus to "emial" element of form dati, using a variable unitl
the 'name'.

document.dati.elements[nome_var].focus();

it don't work, i forget the ( ) above in the exemple, but i used on script,
but it don't work!
 
R

Randy Webb

kirku said:
kirku said:
hello,
i'm not very good with english
i will explain my problem wit an exemple:
// i have a form called dati
var nome_var="email"; //for exemple
ex1=document.dati.elements[nome_var].value //it's ok, work right
document.dati.email.focus( ) //it's ok, work
right
document.dati.elements['email'].focus( ) //it's ok, work right
//but i need something like this:
document.dati.elements[nome_var].focus //IT IS NOT OK

how can i get focus to "emial" element of form dati, using a variable
unitl
the 'name'.

document.dati.elements[nome_var].focus();


it don't work, i forget the ( ) above in the exemple, but i used on script,
but it don't work!

Post the URL to a sample page that displays your problem.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
 
D

denisb

kirku said:
Lee said:
kirku said:
how can i get focus to "emial" element of form dati, using a variable
unitl the 'name'.
document.dati.elements[nome_var].focus();
it don't work, i forget the ( ) above in the exemple, but i used on script,
but it don't work!

pero una cosa cosi :

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> -->
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>dov'e il focus ?</title>
</head>
<body>
<form name="dati">
email : <input type="text" name="email">
nome : <input type="text" name="nome">
cita : <input type="text" name="cita">
</form>
<script type="text/javascript">
var nome_var;
var valore_var;
nome_var = "nome";
valore_var = "alighieri";
document.dati.elements[nome_var].value = valore_var;
alert("primo passagio : " + nome_var + " : " + valore_var);
document.dati.elements[nome_var].select();
nome_var = "cita";
valore_var = "firenze";
document.dati.elements[nome_var].value = valore_var;
alert("secundo passagio : " + nome_var + " : " + valore_var);
document.dati.elements[nome_var].select();
nome_var = "email";
valore_var = "@inferno";
document.dati.elements[nome_var].value = valore_var;
alert("tertio passagio : " + nome_var + " : " + valore_var);
document.dati.elements[nome_var].focus();
</script>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top