Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-01-2013, 05:31 PM   PM User | #1
phpchick
New Coder

 
Join Date: May 2011
Location: new york
Posts: 92
Thanks: 4
Thanked 0 Times in 0 Posts
phpchick is an unknown quantity at this point
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>
phpchick is offline   Reply With Quote
Old 01-01-2013, 06:09 PM   PM User | #2
phpchick
New Coder

 
Join Date: May 2011
Location: new york
Posts: 92
Thanks: 4
Thanked 0 Times in 0 Posts
phpchick is an unknown quantity at this point
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;
			});
phpchick is offline   Reply With Quote
Old 01-01-2013, 06:34 PM   PM User | #3
phpchick
New Coder

 
Join Date: May 2011
Location: new york
Posts: 92
Thanks: 4
Thanked 0 Times in 0 Posts
phpchick is an unknown quantity at this point
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>
phpchick is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:31 PM.


Advertisement
Log in to turn off these ads.