How to prefix value in input

0

I used Bootstrap to insert a typed http: // spam at the beginning of the input.

But I would like to know how to leave the input with this value by default, and then the user only fills the site you want.

<label for="name">SITE
    <div class="input-group">
        <span class="input-group-addon" id="basic-addon3">https://</span>
        <input class="inp-contato" type="text" name="" id="" aria-describedby="basic-addon3" placeholder="Digite seu site," value="value.site"/>
    </div>
</label>
    
asked by anonymous 06.06.2017 / 23:01

1 answer

3

According to what I understood about your question, I made this code to see if that's what you wanted.

jQuery(document).ready(function(){
    jQuery('.inp-contato').on('keypress',function(){
      if(this.value === ''){
          this.value = 'http://';
      }else if(this.value.indexOf('http://') === -1){
          this.value = 'http://';
      }
    })
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><inputclass="inp-contato" type="text" name="" id="" aria-describedby="basic-addon3" placeholder="Digite seu site" value=""/>
    
06.06.2017 / 23:14