How to Add a Telephone Input Field with Country Code & Flag using Pure JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ม.ค. 2025

ความคิดเห็น • 23

  • @RishabhTheHertBrekr
    @RishabhTheHertBrekr 10 หลายเดือนก่อน

    Jeet bhai awesome content❤

    • @CodingDesign
      @CodingDesign  10 หลายเดือนก่อน

      Thank you!. Hope it was helpful.

  • @chinnaratthuengklin2179
    @chinnaratthuengklin2179 10 หลายเดือนก่อน

    Very cool, Thanks a lot bro.

    • @CodingDesign
      @CodingDesign  10 หลายเดือนก่อน

      You're welcome. Hope this video helped you.

  • @adeisaac
    @adeisaac ปีที่แล้ว

    So great, I have been looking for this

    • @CodingDesign
      @CodingDesign  ปีที่แล้ว

      Hope it was helpful to you.

  • @arathabello4763
    @arathabello4763 ปีที่แล้ว

    thank you you're so great :D greetings from Chile :)

    • @CodingDesign
      @CodingDesign  ปีที่แล้ว

      Thanks for watching!
      Hope you'll show your same ❤ & support in future too.

  • @prithviphoenix2
    @prithviphoenix2 10 วันที่ผ่านมา

    Thank you

  • @fadelghani
    @fadelghani 10 หลายเดือนก่อน

    Thank you so much

    • @CodingDesign
      @CodingDesign  10 หลายเดือนก่อน

      You're welcome.
      Hope this video was helpful.

  • @srutisasmal6589
    @srutisasmal6589 ปีที่แล้ว +1

    Great video, great explanation thanks a lot for this but ,I need some help for the last part, like you said if someone types the code country code the flag should change, can you please help with that?

    • @CodingDesign
      @CodingDesign  ปีที่แล้ว +1

      There're 2️⃣problems
      Problem 1️⃣
      If you first enter phone number in your Input field & later if you choose specific option then your "_Input Field's Value_" will be replaced by "_Country Code_".
      ✅Solution:
      ⏏Update code
      function selectOption() {
      input_box.value = phone_code.innerText + input_box.value;
      }
      Problem 2️⃣
      If you enter "COUNTRY CODE" in input field there won't be any ⏏Update (country Flag & Country code).
      ✅Solution:
      input_box.addEventListener('change', updateFlag);
      function updateFlag() {
      this.value = "+" + this.value;
      const matched_code = countries.find(country => country.phone == this.value);
      this.previousElementSibling.querySelector('.iconify').setAttribute('data-icon', `flag:${matched_code.code.toLowerCase()}-4x3`);
      this.previousElementSibling.querySelector('strong').innerHTML = '+' + matched_code.phone;
      };
      ⚠ But I haven't given extra validation so you can try it yourself.

    • @clevertech74
      @clevertech74 ปีที่แล้ว

      @@CodingDesign Hello there, first of thanks for this great project. It'll be great if the user types any country code this change or match the flag+country code on the left too. I know you have explained this above with your solution but it does not work for me, I get the error: Uncaught TypeError: this.previousElementSibling is null, it'll be nice if you could test this and let me know if it really works on your end? Thanks.

  • @ErrorFrag
    @ErrorFrag ปีที่แล้ว

    Nice ❤❤

  • @pramodyadeshan
    @pramodyadeshan ปีที่แล้ว

    Thank you!

  • @jasonjintao
    @jasonjintao ปีที่แล้ว

    how to add () in input blank,i wanna like this (+123),not like this +123

    • @CodingDesign
      @CodingDesign  ปีที่แล้ว

      Within "selectOption" function you can update code
      input_box.value = `(${phone_code.innerText})`;

  • @moao3661
    @moao3661 หลายเดือนก่อน

    bueno tutorial

  • @worldMAINs
    @worldMAINs 11 หลายเดือนก่อน

    Hello, thanks for the video. I'm looking to implement in WordPress and need your help. Thank you in advance for your collaboration!

    • @CodingDesign
      @CodingDesign  11 หลายเดือนก่อน

      Right now I'm sorry to inform you that I won't be able to help you. I'm busy with my college exams.