javascript - Add text to input field (and always replace current text) -


i need help.

i added hidden list input search field. list opens when click input field , closes when click anywhere on body. want add text of list input form when click on it. means text in input field replaced new text list. instance if click on "montego bay" added input field , replace current text in field.

the input field:

<input required id="hotelsplacesean" name="city" type="search" class="form input-lg rtl search-location deleteoutline" placeholder="test" value="<?php echo $themedata->selectedcity; ?>" required /> 

the list:

<div class="suggest-div">          <span class="suggest-content hiddd">             <ul class="liststyle">                <li class="whylist"><b>popular destinations</b></li>                <li class="suggest"><a class="selectlink" href="">montego bay</a></li>                <li class="suggest"><a class="selectlink" href="">negril</a></li>                <li class="suggest"><a class="selectlink" href="">ocho rios</a></li>                <li class="suggest"><a class="selectlink" href="">kingston</a></li>                <li class="suggest" style="border-bottom:0px;"><a class="selectlink" href="">port antonio</a></li>             </ul>          </span>       </div> 

my current javascript (not ideal, know)

<script type="text/javascript">  $(".opensuggest").click(function() {     $(".suggest-content").toggleclass("hiddd");     $("body").click(function() {         $(".suggest-content").addclass("hiddd");     }); });  </script> 

current css:

<style>  a.selectlink {   padding-left: 10px;   padding-top: 10px;   padding-bottom: 10px;   display: block; }  a.selectlink:hover {   color: #fff; }  ul.liststyle {   margin-top: 0px; }  li.whylist {   padding-top: 10px;   padding-bottom: 10px;   background-color: #ddd;   color: #000;   padding-left: 10px;   font-size: 15px;   font-weight: 100;  }  li.suggest {   border-bottom: 1px solid #ddd;   font-size: 15px;   font-weight: 100; }  li.suggest:hover {   background-color: #515b62;   color: #fff; }  .suggest-div {   position: absolute;   width: 100%; }  span.suggest-content {   display: block;   background-color: #fff!important;   margin-top: 0px;   line-height: 1.2;   position: absolute;   width: 100%;   z-index: 999;  }  .hiddd {   display: none!important; }  .form {font-weight: 100!important;} </style> 

i appreciate help, gave best.

use .text() text of link in list, , use .val() replace value of input field.

$(".selectlink").click(function(e) {     e.preventdefault();     $("#hotelsplacesean").val($(this).text()); }); 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -