Reputation: 11
Sorry for being such a beginner but I spent days try to find an answer and now I think your expertise is needed.
I try to do something like "If I click on li, then the text written in li is displayed in a search box (ID '#input#) and automatically the request is launched."
My script works fine but the request/search IS NOT launched.I blocked at the last step of the process.
Thank you very much for your help.
HTML
<ul id="test">
<li>Hello world</li>
<li>Hello world 2</li>
</ul>
Javascript, JQuery
<script type="text/javascript">
$(document).ready(function(){
$("#test li").click(function (){
varindex = $(this).text();
$('#input').val("Text is in the search box!"+" "+varindex);
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#test li").click(function (){
$('#input').focus();
$('#input').trigger(jQuery.Event('key', {which: 13}));
});
});
</script>
Upvotes: 0
Views: 1117
Reputation: 13713
This works:
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js"></script>
<script>
$(document).ready( function () {
$('#test li').click ( function () {
$('#input').attr("value", $(this).text ());
$('#myform').submit ();
});
});
</script>
</head>
<body>
<ul id="test">
<li> Hello world </li>
<li> Hello world 2 </li>
</ul>
<form id="myform" action="xxx.yyy.zz" method="get">
<input id="input" name="myinput" type="text" />
</form>
</body>
Upvotes: 1