0

I want to add a fixed country(UK) code and its not changeable in input box like below image:

enter image description here

And the value +44 is fixed with the other 11 digits. How to add this in input elements.

N.B: +44 also added with other values after submitting the form.

Shawn
  • 1,232
  • 1
  • 14
  • 44
  • 1
    Ha ve you tried something? Please show us your code. – Sfili_81 Dec 10 '19 at 12:43
  • Does this answer your question? [Do you know any opensource JQuery dropdown menu for telephone prefix?](https://stackoverflow.com/questions/11204479/do-you-know-any-opensource-jquery-dropdown-menu-for-telephone-prefix) – Sfili_81 Dec 10 '19 at 12:44

2 Answers2

2

You'll need to add another element that'll work as a prefix for this input.

#input-wrapper * {
  position: absolute;
}

#input-wrapper label {
  z-index: 99;
  line-height: 25px;
  padding: 2px;
  margin-left: 5px;
}

#input-wrapper input {
  height: 25px;
  text-indent: 35px;
}
<div id="input-wrapper">
  <label for="number">+44</label>
  <input id='number' onchange="this.value = '+44' + this.value" type="text">
</div>

If you want the +44 to be added without showing up in HTML, you can add an event in JS file.

document.getElementById("number").addEventListener('change', function(e){
    e.target.value = '+44' + e.target.value;
});
Akash Shrivastava
  • 1,365
  • 8
  • 16
1

You can position the text on top of the input field to make it look as if it is inside it. Something like this:

<input type="text" name="phone" style="width:3.5em;padding-left:1.5em;font:inherit"><span style="margin-left:-3em;margin-right:10em;">+44</span>
Joykal Infotech
  • 1,840
  • 3
  • 9
  • 17