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!

determine which button is used if user hits [enter]

Status
Not open for further replies.

TKaeser

Technical User
Mar 4, 2002
16
CH
TKaeser (TechnicalUser) May 23, 2002
Hello,

I've asked this question before in the PHP forum, but maybe didn't make it quite clear. (Thread216-245486)

I have a form that contains 4 different submit buttons with the same name and different captions.
If the user hits his enter-key the form is always submitted by button 1. How can I change this? (to an arbitary button...)

Thanks!

Thomas
 
Hi Thomas,

I made some quick changes in your code you posted in the javscript forum.
Maybe it points you in the right direction?

My thought is to make an extra text field (type1).

With the sel-buttons you make a preselection and fill the text field. (the return false; prevents the form to submit when you click)

Use the type1-value (instead of the sel-value) to handle your PHP-script.

Advantage is that you don't have to use the document.dataform.sel[6].select(); because it do not work in IE4.

Here is the code (I didn't test it)

<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
</HEAD>
<BODY>

<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' onclick=&quot;PreType(this);return false;&quot;><br>
<br>
<input type='submit' class=&quot;navigate&quot; name='sel' value='rücknahme' onclick=&quot;PreType(this);return false;&quot;><br>
<input type='submit' class=&quot;navigate&quot; name='sel' value='geräte' onclick=&quot;PreType(this);return false;&quot;><br>
<input type='submit' class=&quot;navigate&quot; name='sel' value='bezogene' onclick=&quot;PreType(this);return false;&quot;><br>
<input type='submit' class=&quot;navigate&quot; name='sel' value='am lager' onclick=&quot;PreType(this);return false;&quot;><br>
<input type='submit' class=&quot;navigate&quot; name='sel' value='personen' onclick=&quot;PreType(this);return false;&quot;><br>
<input type='submit' class=&quot;navigate&quot; name='sel' value='verwaltung' onclick=&quot;PreType(this);return false;&quot;><br>
<input type='submit' class=&quot;navigate&quot; name='close' value='exit' onClick=&quot;shutdown();return false;&quot;>
<br><br>
<input type=&quot;text&quot; name='type1'>
<input type='submit' class=&quot;navigate&quot; name=&quot;sfdef&quot; value=&quot;submit form definitely&quot; onclick=&quot;document.dataform.submit();&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;check();return false;&quot;>
</td>
</tr>
</table>
</form>
<script language='JavaScript' type='text/javascript'>
function PreType(Fvalue)
{
document.dataform.type1.value = Fvalue.value;
}

function check()
{
}

function shutdown()
{
}

//document.dataform.sel[6].select();
document.dataform.machine.focus();
</script>
</td>
</tr>
</table>


</BODY>
</HTML>

Hope this helps you in the right direction,
Erik
<!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (!! Many Happy Returns !! -->
 
Thank you for your efforts Erik, I appreciate that very much!

It's a good solution, but not exactly what i wanted...

Instead I've rewritten my php scripts to use multiple forms, put every button in a separate form and added a little bit of js - works now!

next time i'll know

Best regards
Thomas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top