Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2011
    Location
    new york
    Posts
    104
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Search box not working properly when push enter

    I have a search box built in JQuery that displays a dynamic window, that only works when you click the little "Go" button.

    If you hit enter on the keyboard, the js thinks you're hitting the 'search' button of the dynamic window instead. I was wondering if anyone could help me with this.

    Here is the link to live

    http://goo.gl/A0LRu


    and here is the code. I can't seem to figure out the problem.




    Code:
    	<script>
    			jQuery('#quick-search-form a.button').click(function(){
    				var symbol = jQuery('#symbol').val();
    				if (symbol != "") {
    					jQuery('#popout').show();
    					jQuery('#quick-search-form .error');
    				} else {
    					jQuery('#quick-search-form .error').remove();
    					jQuery('#quick-search-form').append('<div class="error">Symbol required</div>');
    				}
    				return false;
    			});
    			jQuery('#quick-search-form a.close').click(function() {
    				jQuery('#popout').hide();
    			});
    			jQuery('#quick-search-form form').submit(function() {
    				jQuery('label', this).removeClass('error');
    				var do_search = true;
    				if (jQuery('select[name="category"]', this).val() == '') {
    					jQuery('label[for="category"]', this).addClass('error');
    					jQuery('.required', this).show();
    					do_search = false;
    				}
    				if (jQuery('select[name="subcategory"]', this).val() == '') {
    					jQuery('label[for="subcategory"]', this).addClass('error');
    					jQuery('.required', this).show();
    					do_search = false;
    				}
    				if (jQuery('select[name="expected_deviation"]', this).val() == '') {
    					jQuery('label[for="expected_deviation"]', this).addClass('error');
    					jQuery('.required', this).show();
    					do_search = false;
    				}
    				if (jQuery('select[name="expected_outlook"]', this).val() == '') {
    					jQuery('label[for="expected_outlook"]', this).addClass('error');
    					jQuery('.required', this).show();
    					do_search = false;
    				}
    				return do_search;
    			});
    			
    		</script>

  • #2
    Regular Coder
    Join Date
    May 2011
    Location
    new york
    Posts
    104
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I believe that this is the code that is controlling the popout menu

    Perhaps we should make that ".click" part receive both click and enter? but I'm not sure how to do this...

    Code:
    			jQuery('#quick-search-form a.button').click(function(){
    				var symbol = jQuery('#symbol').val();
    				if (symbol != "") {
    					jQuery('#popout').show();
    					jQuery('#quick-search-form .error');
    				} else {
    					jQuery('#quick-search-form .error').remove();
    					jQuery('#quick-search-form').append('<div class="error">Symbol required</div>');
    				}
    				return false;
    			});

  • #3
    Regular Coder
    Join Date
    May 2011
    Location
    new york
    Posts
    104
    Thanks
    4
    Thanked 0 Times in 0 Posts
    So I'm using a workaround that basically disables the enter button. Can anyone see any side effects of doing this?



    <script type="text/javascript">

    function stopRKey(evt) {
    var evt = (evt) ? evt : ((event) ? event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
    }

    document.onkeypress = stopRKey;

    </script>


  •  

    Posting Permissions

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