5

I am working on an mvc application. Two tables each have their individual submit button. Table1 has default submit on enter key. How do I change the submit button based on textbox focus?

<table>
...<td align="left"><%= Html.TextBox("name")%></td>
...<input id="nameSubmit" name="NameSubmit" type="submit" value="Search"/>
</table>
<table>
...<td align="left"><%= Html.TextBox("idNum")%></td>
...<input id="idSubmit" name="IdSubmit" type="submit" value="Search"/>
</table>

I tried using the panel, but "the DefaultButton of 'Panel1' must be the ID of a control of type IButtonControl".

Any ideas?

MrM
  • 21,709
  • 30
  • 113
  • 139
  • 2
    possible duplicate of [How is the default submit button on an HTML form determined?](http://stackoverflow.com/questions/925334/how-is-the-default-submit-button-on-an-html-form-determined) – Darin Dimitrov Feb 23 '11 at 20:13
  • @zzzzBov Let us consider the tooltip on the downvote button: "This question is unclear or not useful". Give the OP a break. :P – Dan J Feb 23 '11 at 20:34
  • @djacobson, I've had this come up before; And you can read [my policy on misused table elements here](http://stackoverflow.com/questions/5009718/red-dot-similar-to-li-element-in-html). – zzzzBov Feb 23 '11 at 20:38
  • @zzzzBov - I just wanted to paint a picture of what I am working with. You consider it worthy of a down vote, acknowledged. – MrM Feb 23 '11 at 21:10
  • @zzzzBov I appreciate the elucidation of your policy. My disagreement with it remains. In the OP's words, acknowledged. – Dan J Feb 23 '11 at 21:21

1 Answers1

6

If you wrap each of the submits in <form> tags that should help determine which submit was clicked as such:

<table>
    <form id="form1">
        <td align="left"><input id="name" /></td>
        <input id="nameSubmit" name="NameSubmit" type="submit" value="Search"/>
    </form>       
</table>
<table>
    <form id="form2">
        <td align="left"><input id="number" /></td>
        <input id="idSubmit" name="IdSubmit" type="submit" value="Search"/>
    </form>
</table>

This would make any Enter presses while the textbox was focused submit to the corresponding form.

Here is a demo of this working, I hope that it helps you out.

Rion Williams
  • 74,820
  • 37
  • 200
  • 327