简体   繁体   中英

Can't assign a new value to my autocomplete box

I've created a search page that can be toggled between french and english. So when the user searches a record and toggles to french it displays the same record they were viewing on the english page.

What I want to do is display the record name in the search box when the page is toggled.I assumed it was as simple as doing a $('#inputID').val(record); but it doesn't seem to be working. I've alerted the record name and it works fine, so I'm stumped. All the scripts are linked correctly as well so that's not the problem.

Autocomplete Box Code

<div id="ui-widgit">
  <label for="searchParams">
  <h1>Search All Programs (By Screen Number or By Error Code):</h1>
  </label>
  <input type="text" id="inputID" name="inputID" value="" class="ipt_Design" style="width:255px;" />
  <input type="button" value="Search" name="searchBtn" class="btn_Design" onclick="showSearch(inputID.value)"/>
</div>

Try to change the value of inputID with this

$('#inputID').val(recordToggle);

also have tried this:

$('#inputID input').val(recordToggle);

It is hard to tell with your presented markup but I am assuming you are trying to change the value of $('#inputID') after the page refreshed. It is important where you put this code. If it is placed before <input type="text" id="inputID" name="inputID" value="" class="ipt_Design" style="width:255px;" /> <input type="text" id="inputID" name="inputID" value="" class="ipt_Design" style="width:255px;" /> you will not return anything with $('#inputID') so you will change the value of nothing to your text. It will give no error. To fix this you can use:

$( document ).ready(function(){
  $('#inputID').val(recordToggle);
});

Be sure to read about jQuery's ready function because load may be the better choice.

If this doesn't fix your problem let me know. I will update my answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM