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

Making my form submit link the defaul

Status
Not open for further replies.

samoff

Programmer
Aug 16, 2000
15
GB
I have a form which is submitted by a link with a call to submit(). It all works fine.

My problem is that I can't make this link the default action when a user fills in the form and presses [Enter].
My page has two such forms - I need a solution that knows which form to submit.

ta very much.


sam

http:
 
use keydown, when u have a submit button it is enabled by default, if there is no submit button then:
<input type="text" ...... onkeydown="event.keyCode==13?submit():''">


this is assuming that keycode of "Enter" is 13...

Known is handfull, Unknown is worldfull
 
I can help you on knowing whether the user has pressed 'Enter'.

Have a function which checks the key pressed.

function checkEnter()
{
if(window.event.keyCode == 13)
{
document.formName.submit();
}
}

However as you have 2 forms i'm not sure how you can capture which form the user is in.

If you had 1 form, between the <script> tags i'd put
document.onKeyUp = "checkEnter()"
to perform the function above.

The only thing I can suggest at the moment is that on every input field you have and depending which input fields are in which form have individual calls to 2 different functions.

-Functions.
// To submit form1
function firstFormEnter()
{
if(window.event.keyCode == 13)
{
document.form1.submit();
}
}

// To submit form2
function secondFormEnter()
{
if(window.event.keyCode == 13)
{
document.form2.submit();
}
}


-For form1.
<body>
<form name="form1">
<input type="text" name="text1" onKeyUp="firstFormEnter();">
</form>
</body>

-For form2.
<body>
<form name="form2">
<input type="text" name="text2" onKeyUp="secondFormEnter();">
</form>
</body>


hth

Stewart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top