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

Make 2nd submit button the default on Enter

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
I have a form with two buttons. The first expands the data entry area (i.e. adds input fields to the existing window). The second is effectively the 'true' submit button that equates to 'go ahead and validate'.

I have seen several references throughout this forum but am confused about the possibilities and the definitive answer as to how I would make my second button the default when the enter key is pressed. Options appear to include, use of tabindex, use javascript, change order of the buttons (which I can't really do).

The symptoms at the moment are that, when the user hits the enter key, the first button is triggered and the data entry area is expanded.

Can anyone help spell it out for me please?

Thanks in advance.
 
How about setting focus ?, onload or on click of the first button.

Code:
<form>
<input type="Button" value="Expand" onClick="this.form.two.focus()">
<input type="Submit" value="Submit" id="two" onclick="alert('Enter Was Pressed');">
</form>
 
Thanks for the replies.

cLFlaVA: I need the button to 'activate' the server (ASP) which will then generate the HTML for the updated page showing the additional input controls so I don't think this would work. But maybe I'm missing something?

Fendal: My above comment re server may be relevant. I don't think I understand your suggestion, sorry.

Could I do it via a link to the ASP page in question rather than a submit? Would this still 'post' the data?

Perhaps I should be posing the question in the ASP forum.
 
I have implemented a workaround by including a third button (prior to the other 2 in the form) which is invisible (CSS zero width ) which triggers the same server action as the existing Submit button. It therefore effectively becomes the default.

What is lost of course is any visual indication as to which bitton is the default - i.e. no highlighting - as the highlighted button is not visible.

Not ideal but I can live with it.
 
couldn't you add javascript to the generated update of the page, which would contain the set focus script ?.

I'd probably need to see it to understand it completely.
 
I have my workaround in place and it's behaving more or less as I want it so I think I'll stick with it on the basis that 'if it ain't broke, don't fix it'.

Thanks anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top