Link to call in phone numbers

Asked

Viewed 2,065 times

1

I have a form where several user information are registered, including phone numbers and, after registering, you can view the registration by opening a form like the previous one with disable fields equal to fields filled at the time of registration

I would like to turn this number into a link so that the user can call the form number if he is on a mobile device and I thought I would just put a href , but as I’m taking this information from the bank and throwing it into a text box, I don’t know how to turn into a link.

<div class="form-group col-md-6">
		<label for="telefone">Telefone:*</label>
		<div class="input-group phone">
		  <span class="input-group-addon"><i class="glyphicon glyphicon-earphone"></i></span><input required type="phone" class="form-control" id="telefone" name="telefone" placeholder="Digite o seu telefone:" value="<?=$row['telefone'];?>" disabled>
		</div>
	</div>

inserir a descrição da imagem aqui

I went to try href anyway and it stayed like this: inserir a descrição da imagem aqui

Can someone give me an idea of how to do this?

  • 1

    You can even link one input who is disabled. However the click event will not have effect, precisely because the field is disabled. I think to solve this Javascript goes well.

  • Probably it would be the case to exchange the input for a simple <a>, and stylize as if it were a field, or even put the <a> in the phone icon instead of the text. It depends on the ultimate goal. If it is really an anchor, the actual <input> would not even be the correct element.

3 answers

7

Just print the value in the href of the A tag.

For example:

 <a href="tel:<?=$row['telefone'];?>"><?=$row['telefone'];?></a>

You may need to remove the special characters from href if it does not work in a specific browser. For this you can use:

 <a href="tel:<?=preg_replace('/[^0-9]/', '', $row['telefone']);?>"><?=$row['telefone'];?></a>

I hope I’ve helped.

4

You can try:

<a href="tel:55-5555-12345">(55) 5555-12345</a>
  • So, I could do so if it were a fixed number, like a footer. But in case I’m taking this number from a table in my database,

  • 1

    @Marianaferreira you will need to normalize.

0


How do you want the click to work on a input, and not in a anchor, I suggest creating a click event in your input, through javascript.

Add the onclick property to the input:

onclick="window.open('tel:<?=$row['telefone'];?>');";

Would look like this:

<div class="form-group col-md-6">
    <label for="telefone">Telefone:*</label>
    <div class="input-group phone">
        <span class="input-group-addon"><i class="glyphicon glyphicon-earphone"></i></span><input required type="phone" class="form-control" id="telefone" name="telefone" placeholder="Digite o seu telefone:" value="<?=$row['telefone'];?>" disabled onclick="window.open('tel:<?=$row['telefone'];?>');">
    </div>
</div>
  • 1

    It worked really well, thank you. Obs: It’s Jaskier in this picture of you?

  • 1

    Not at all! No, it’s The Witcher’s Dandelion =) (Edit: I haven’t read the books yet, I hear it’s called Jaskier, so yes hehe)

Browser other questions tagged

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