1

I have the following code, in mydata.jsp value of q is empty. What is the correct way to pass value of inputId to mydata.jsp?

<input type="text" size="25" name="inputId" id="inputId" />

and Jquery script as

 <script type="text/javascript">
$(function() {
    $("#inputId").autocomplete({

        source: "mydata.jsp?q="+$( "#inputId" ).val(),
        select:function(event,ui) {
            $("#hid").val(ui.item.email)
        }
    });
});


</script>

2 Answers 2

2

When you pass $( "#inputId" ).val() as an argument to .autocomplete(), you're getting the initial value from that field before anything has been typed. That would explain why it is empty.

If you use the string version of autocomplete, it can automatically add the typed value to the URL. See the doc for the string version of source here.

If you want the URL for the source to be a dynamically generated URL, then you can also pass a function as the source and the code in that function can generate the URL/alternatives. See the doc for the source option here.

Sign up to request clarification or add additional context in comments.

2 Comments

How can I pass the value of inputId to mydata.jsp?
In the doc, see the string option for the source property. The autocomplete method will automatically add the current value of the typed term.
1
 $('#inputId').keyup(function()
{
var str=$(this).val();
if(str!='')
{
  $.ajax({
      type:"GET",
      url:"mydata.jsp",
      data:"str="+str,
      success: function(data){
          alert(data);
     }

  });
}
});

Try like this. hope it will give you some solution.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.