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

set default focus on submit button

Status
Not open for further replies.

TKaeser

Technical User
Mar 4, 2002
16
CH
Hello,

I have a form with multiple submit buttons (all the same name, different values - for php postprocessing) and a text field.

What I want:
user enters data and hits enter and the form is submitted by the submit button which i 'preselect', in this case button[7].

What happens:
i have managed to set the focus onto the desired submit button by using

Code:
 window.dataform.button[7].select();

but when the textfield gets the focus, the 'preselection'
jumps to button[0] (first in array) and is therefore used, when the user hits <[enter\].

Any idea how to set 'preselection' explicitly?

Thanks!
Thomas
 
Ok, here's the code:
Code:
<form name=&quot;dataform&quot; action=&quot;machineshop.php3&quot; method=&quot;get&quot;>

<table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;800&quot;>
<tr>
<td>
<img src=&quot;graphics/logo.gif&quot; width=&quot;180&quot; height=&quot;38&quot; alt=&quot;&quot;>
<br>
<input type='submit' class=&quot;navigate&quot;  name='sel' value='ausgabe'><br>
<br>
<input type='submit' class=&quot;navigate&quot;  name='sel' value='rücknahme'><br>
<input type='submit' class=&quot;navigate&quot; name='sel' value='geräte'><br>
<input type='submit' class=&quot;navigate&quot; name='sel' value='bezogene'><br>
<input type='submit' class=&quot;navigate&quot; name='sel' value='am lager'><br>
<input type='submit' class=&quot;navigate&quot; name='sel' value='personen'><br>
<input type='submit' class=&quot;navigate&quot; name='sel' value='verwaltung'><br>
<input type='submit' class=&quot;navigate&quot;  name='close' value='exit' onClick=&quot;shutdown();&quot;>
</td>
<td class=&quot;main&quot;>
   <table class=&quot;checkout&quot; cellspacing=5 cellpadding=5 border=1>
   <tr>
   <td>Gerat</td>
   <td><input type='text' name='machine' value='' size='12' maxlength='3' tabindex=&quot;1&quot;></td>
   </tr>
   <tr>
   <td>Bezuger</td>
   <td><input type='text' name='perso' value='' size='12' maxlength='3' tabindex=&quot;2&quot;></td>
   </tr>
   <tr>
   <td colspan=&quot;2&quot;>
   <br>
   <input type='submit' name='sel' value='checkout' tabindex=&quot;3&quot; onClick=&quot;return check()&quot;>
   </td>
   </tr>
   </table>
<script language='JavaScript' type='text/javascript'>
window.document.formular.sel[7].focus();
window.document.formular.machine.focus();
</script>
</td>
</tr>
</table>

i thought, if i set focus on the button first and then on the textfield, maybe the button would be set to react to [enter]...


and here's what i mean by 'preselection'

preselection.gif



i hope it got clearer now!

cheers
thomas
 
forgot to say:

if the user hits [enter] after filling the 'Bezuger' field the form is submitted by 'ausgabe' instead of 'eintragen'...

thanks
thomas
 
Hi
I have the same problem. have you solve the problem ? How ?
Thanks for your help.

Stéphane
 
Try this:

1. Change all <input type='submit' ...> to this:
<input type='button' ... onclick=&quot;changeValue(this)&quot;>

2. Add ONE Submit button:
<input type=submit name=&quot;thesubmit&quot;>

3. Then add this function:

function changeValue(clicked)
{
document.dataform.thesubmit.value = clicked.value;
document.dataform.submit();
}

4. You'll also need to make the Submit button invisible or non-functioning (if you want a user to click only your buttons). Use any method you like to achieve this, like style=&quot;display:none&quot; or some other.

The script will pass the value of a clicked button to the _real_ Submit button and then will submit a form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top