Results 1 to 3 of 3

Thread: HTML Input boxes submit themselves???

  1. #1

    Thread Starter
    Lively Member benski's Avatar
    Join Date
    Sep 1999
    Location
    UK
    Posts
    126

    Unhappy

    I am confused by something that's happening with some asp pages I am editing.

    I effectively just have a search box "frmSearch" and a button "btnSearch" which submits the form.

    When I press {ENTER} in "frmSearch" the form is submitted. Why? How can I stop this happening?

    Thanks!

  2. #2
    Member
    Join Date
    Aug 2000
    Location
    Florida
    Posts
    45
    I think this is the default behavior for a form when you have a submit button. Perhaps, change the type to button and code an onClick event.
    If I could only remember my name...

  3. #3

    Thread Starter
    Lively Member benski's Avatar
    Join Date
    Sep 1999
    Location
    UK
    Posts
    126

    Talking

    Yeah- I meant, when I press {ENTER} in the input box, not press the button.

    The button is already a "button" not a "submit".

    I have found a workaround for this behaviour though:

    Check if they've pressed the {ENTER} key (keycode 13) then cancel the event if necessary.

    Code:
    sub frmSearch_onkeypress()
    
    	if document.theform.frmSearch.value = "" and window.event.keyCode = 13 then '{enter} key pressed with no data in input box
    		msgbox "You have not entered a search string!",0
    		window.event.returnValue = false
    	end if
    
    	if window.event.keyCode = 13 then
    		window.event.returnValue = false
    	end if
    
    end sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width