Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Submit a form onclick with Jquery autocomplete

Posted on 2010-09-10
11
Medium Priority
?
1,655 Views
Last Modified: 2012-05-10
I'm using jquery autocomplete on a search form. I would like the form to submit when a result is clicked. IE: No submit button.

Current code is below.

Thanks in advance.
<script type="text/javascript">
$().ready(function() {

	function log(event, data, formatted) {
			$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
		}
		
		function formatItem(row) {
			return row[0] + " (<strong>id: " + row[1] + "</strong>)";
		}
		function formatResult(row) {
			return row[0].replace(/(<.+?>)/gi, '');
		}
		
		$("#tablesearch").autocomplete("ajaxsearch.asp", {
			width: 260,
			selectFirst: true

		});




		$("#tablesearch").result(function(event, data, formatted) {
			if (data)
				$(this).parent().next().find("input").val(data[1]);
		});

	})
</script>


'here is the form

<form name="search" action="users_add.asp" method="post" autocomplete="off"><input type="text" name="tablesearch" id="tablesearch" /><input name="submit" type="submit" value="Get" /></form>

Open in new window

0
Comment
Question by:griffaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
11 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 33651302
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33651310
sorry forget my comment, bad thread...
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33651336
If each result have a class : resultClass

You should be able to use something like :

(where myForm is the id of the form)
$(".resultClass").click(function() { $("form[name='search']").submit(); });

Open in new window

0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 82

Expert Comment

by:leakim971
ID: 33651340
(where myForm is the id of the form)
$(".resultClass").click(function() { $("#myForm").submit(); });

Open in new window

0
 

Author Comment

by:griffaw
ID: 33653115
leakim971:

Tried it. Didnt work. Any other thoughts?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33653402
Can I see your implementation of the proposition ?
0
 

Author Comment

by:griffaw
ID: 33653433
See below. I also need to populate a hidden form field named "editid". I need to pass the id rather than the label.

Thanks!
<script type="text/javascript">
$().ready(function() {

	function log(event, data, formatted) {
			$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
		}
		
		function formatItem(row) {
			return row[0] + " (<strong>id: " + row[1] + "</strong>)";
		}
		function formatResult(row) {
			return row[0].replace(/(<.+?>)/gi, '');
		}
		
		$("#tablesearch").autocomplete("ajaxsearch.asp", {
			width: 260,
			selectFirst: true

		});


		$("#tablesearch").result(function(event, data, formatted) {
			if (data)
				$(this).parent().next().find("input").val(data[1]);
		});
		
		$(".resultClass").click(function() { $("#searchform").submit(); });


	})
</script>


///////form

<form name="searchform" id="searchform" action="users_add.asp" method="post" autocomplete="off"><input type="text" name="tablesearch" id="tablesearch" /><input type="hidden" name="editid" id="editid" /><input name="submit" type="submit" value="Get"/></form>

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 33653489
I don't see where you're setting the class : resultClass
To be able to use : $(".resultClass").click
0
 

Author Comment

by:griffaw
ID: 33653581
Sorry...do you mean setting the class on the form?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33653597
>Sorry...do you mean setting the class on the form?

No, you said : I would like the form to submit when a result is clicked. IE: No submit button.

So you need to set "resultClass" on each "result"
0
 

Author Comment

by:griffaw
ID: 33653883
Sorry if im dense...could you please post the code?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question