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

Setting Default button

Status
Not open for further replies.

GreyCat

Programmer
Jul 7, 2000
6
CA
Does anyone know how to set a default button in html?

I mean the one that gets pressed when the user hits enter on a web page.

 
So I guess nobody knows how to set a default button in html. Well if anybody has any idea could you please post it cause I'm stuck.
 
Dear GreyCat,

I don't believe there is a notion of 'default button' in HTML. However if you create an input tag of type 'submit' it will be a button and you can place whatever you like in the 'value' attribute, i.e.:

<input type=&quot;submit&quot; value=&quot;I am the default!&quot;>

Of course I believe this also only works inside a <form></form> element but I'm not sure about that.

I don't know about browser compatability but I think it works in IE and 'The other' browser.

Hope this helps
-pete
 
yes, it must be inside a form: <form name=frmMain action=&quot;page that handles the form submission&quot; method=post>

also, netscape won't automatically submit when the enter button is pressed
 
I'm mainly coding for explorer and I often have multiple submit buttons on my forms. Is there anyone know any other way?
 
If the button does not physically get pressed, its value is not submitted. You would have to test the form's submission by looking at a textbox, checkbox, etc. value.

First, test if a button was pressed, then if no buttons were pressed, but information was submitted (a textbox value for instance), you choose yourself what you want the default function to be.

For instance, if you had a combo box with employee id numbers in it, a delete button, and an edit button.

Your code would look something like this:

If request(&quot;editbutton&quot;) = &quot;Edit&quot; then
'allow user to edit that employee
ElseIf request(&quot;deletebutton&quot;) = &quot;Delete&quot; then
'delete that employee
ElseIf request(&quot;combobox&quot;) <> &quot;&quot; then
'you choose what you want to do as the default, whether it be editing or deleting
End If
 
Dear FroggerIII

I don't know about netscrap (which I am not coding for) (all are internal scripts) but in IE5.5 when you press enter button the html button that decides to get pressed does pass its name value pair!

But I think palbano had it mostly right - I found that if you had multiple buttons in your form you could make all except one of type=&quot;button&quot; and have only one of type=&quot;submit&quot; and the submit button will be what gets pressed when the enter button is pressed.

Any other experiences on this problem would be appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top