Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2004
    Location
    Phnom Penh
    Posts
    9

    Unanswered: Problem with Enter Key to submit form

    Dear all,

    I have a problem with enter key to submit form. For example,

    I have one textfiled and one submit button for my search form with method "get".

    When i filled in the keywork into the textfiled and press "Enter Key" the value passing in IE address bar is just only http://localhost/search.asp?txt_keyword=mekong

    so that does not work if i use the below code to fire my search event,
    .........................................
    if request("submit") <> "" then
    .........................................
    .........................................

    That is different, and it work if i click on submit button. IE address bar show, http://localhost/search.asp?txt_keyw...&Submit=Search

    But i think that most users will press "Enter Key" are much more convinient, right?

    Anyone could help me on this issue?

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Why are you checking for the clicking of the "Search" button?

    Instead search for the presence of a search criteria (eg. your keyword).

    The advantage with this is that you can then send url's to people to show the search results directly, rather then forcing the user to have to go to the search page and enter the keyword themselves.

    So instead of

    Code:
    if request("submit") <> "" then
    use

    Code:
    if request("txt_keyword") <> "" then

  3. #3
    Join Date
    Jan 2004
    Location
    Phnom Penh
    Posts
    9
    Thanks for your help.

    So the seach button, pass its value only when user click on it ? no customize on the form that could do that (pess the key Enter and also pass the value of search button)?

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Yes. The search button will only pass a value if it is clicked.

    You could create some javascript catch the submit via the Enter key and then pass a value to the search results page, but really it is more trouble then it is worth IMO.

    Just check for a search criteria (eg. a keyword) and forget the rest would be my advice.

  5. #5
    Join Date
    Dec 2003
    Posts
    454
    Ignore the difference between pressing Enter key and clicking the button "Submit". Like rokslide said, you can not use Request("Submit") <> "" to make a decision that the sumbit button is clicked. I give you an example. On the form, there are two buttons, "Save" and "Preview", which both submit the form. Since the both buttons have their values, you can not know which button is clicked base on Request("Submit") <> "". You need to use another way to check it.

  6. #6
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    That's not quite right gyuan (okie, so it is right, but it's a little misleading)

    On the form, there are two buttons, "Save" and "Preview", which both submit the form. Since the both buttons have their values, you can not know which button is clicked base on Request("Submit") <> "".
    Each button with have a different id eg btnSave and btnPreview and you would have to request those values to determine what was pressed eg...

    [code]
    If Request("btnSave") = "Save" then myAction="Save"
    If Request("btnPreview") = "preview" then myAction="Preview"
    [code]

    The fact that they both submit should not confuse the issue.

    My statement still stands though. If you arrive on the page with a search criteria, then do a search (weather the Search button was clicked or not).

  7. #7
    Join Date
    Jan 2004
    Location
    Phnom Penh
    Posts
    9
    Thanks to Rockslide and Gyuan!!! for your help!!!

    Cheers!!!

Posting Permissions

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