How to prefix value in input

Asked

Viewed 51 times

0

I used Bootstrap to insert spam written http://right 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>

1 answer

3

According to what I understood regarding your question, I’ve drawn up this code see if this is 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>
<input class="inp-contato" type="text" name="" id="" aria-describedby="basic-addon3" placeholder="Digite seu site" value=""/>

  • I think he doesn’t want the value to appear inside the field, after all the same is already displayed by the boostrap he created.

  • I understand, I may have misunderstood, I will await his return.

  • Exactly as José said, I need to send him without him appearing in the field. :/

  • So it needs to be done at the time of sending, you will do this sending via Submit or ajax, put more information.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.