Hit 'ENTER' is a text box - sumits the f

Results 1 to 3 of 3

Thread: Hit 'ENTER' is a text box - sumits the f

  1. #1
    simhan Guest

    Default Hit 'ENTER' is a text box - sumits the f

    Hi,<BR>my problem is, I have a search box followed by a search button. I call funsearch() on click of search button.<BR>I have trapped the &#039;ENTER&#039; key in the search box and iam calling the same funsearch() function.<BR>The functionality of funsearch is to check for a value in the search box and if a value is there then submit the page with the value, else display an alert.<BR>When I call funsearch on click of search button, with no value in the search box, then the alert gets displayed.<BR>If I call the same funsearch on hitting &#039;ENTER&#039; in the search box with no values in the search box ofcourse,then the alert gets displayed and also the page gets submitted. I don&#039;t want to submit the page and also donot want to handle &#039;no vlaues entered in the search box&#039; alert on the server side.<BR>Can you help me please.<BR>Thanks in advance<BR><BR>simhan

  2. #2
    Join Date
    Dec 1969

    Default RE: Hit 'ENTER' is a text box - sumits t

    Change the function from the OnClick event of the button to the onSubmit event of the form.<BR><BR>That way before the form is submitted BY ANY MEANS (except using javascript with document.formname.submit()).<BR><BR>But remember to RETURN a value.<BR><BR>i.e.<BR><BR>==== START<BR>&#060;form action="x.asp" method="post" onSubmit="return funsearch()" name="searchForm"&#062;<BR>&#060;input type="text" name="search"&#062;&#060;/form&#062;<BR>&#060;script&#062;<BR>function funsearch(){<BR> if(document.searchForm.search.value == ""){<BR> alert(&#039;You must write something&#039;);<BR> return false;<BR> }else{<BR> return true;<BR> }<BR>}<BR>&#060;/script&#062;<BR>==== END<BR><BR>Craig.

  3. #3
    Join Date
    Dec 1969

    Default How do you trap the ENTER key ?

    I have a similar thing, where I type into a text box, but my users keep pressing ENTER instead of clicking on the search button, how do I make the ENTER key = The Search button value &#062;?

Posting Permissions

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