I have a text box on a website that displays a phone number. I'd like to have a link next to the text box (or underneath, doesn't matter) that says "Click to call". I want that link to call whatever phone number is displayed in the text box, but I can't figure out how to actually get that number into the tel: element. Can I just take the name of the text box and put that as the "tel:"?
Here's the text box:
<input name="txtPhone" type="text" id="txtPhone" onkeydown="javascript:ShowSave();" onchange="javascript:ShowSave();" style="width:120px;">
Can I just do something like this:
<a href="tel:[txtPhone]" >Click to call</a>
Or is that not possible or would I have to change the input type to "tel:"?
I apologize ahead of time as my knowledge of html is extremely limited.
In the solution below, the value of the
phoneValuevariable is updated as long as there is a data input to the<input>element. When the<a>element's click event fires, the<a>element'shrefattribute is assigned the phone number entered in the<input>element. Fill in theisValid()method to verify the phone number.