How can use the last 3 digits of the provided phone number as the unique ID

  • ikhwanasli
    Asked on October 20, 2015 at 12:25 PM

    what if i use text box for input phone number.  how can i collect the last 3 digits of the provided phone number? 

    http://form.jotform.me/form/52924533034451

  • Boris
    Replied on October 20, 2015 at 12:58 PM

    I'm afraid that still the only solution is to use your form's source code, and add a custom script inside the source code of your form. The script you would need to add to your source code would be similar to the one my colleague used in the previous thread:

    <script type="text/javascript">

    function populateId() {
        var phone = document.getElementById("HTML-ID-of-your-phone-field").value,
            converted = phone.toString();

        if (phone != "") {
            document.getElementById("HTML-ID-of-your-Unique-ID-field").value = converted.substr(-3, 3);
        }
    }

    </script>

    You can get the proper HTML IDs of your fields by following this guide: How to find Field IDs & Names. If your phone field is the one named Nomor HP on your form, and your unique ID field is the one named 3 Digit HP, you would adjust that script with the proper HTML IDs:

    <script type="text/javascript">

    function populateId() {
        var phone = document.getElementById("input_4").value,
            converted = phone.toString();

        if (phone != "") {
            document.getElementById("input_6").value = converted.substr(-3, 3);
        }
    }

    </script>

    You also need to add onDISABLEDkeyup="populateId(); to the field where your users would be entering their phone number. So if you were collecting phone numbers in the field named Nomor HP on your form, you would need to replace this part of your form's source code:

    <input type="text" class=" form-textbox validate[required]" data-type="input-textbox" id="input_4" name="q4_nomorHp" size="60" value="" />

    with this:

    <input type="text" class=" form-textbox validate[required]" data-type="input-textbox" id="input_4" name="q4_nomorHp" size="60" value="" onDISABLEDkeyup="populateId(); />

    I hope this helps. Please let us know if you need further assistance, and we will be happy to assist.

  • ikhwanasli
    Replied on October 20, 2015 at 9:28 PM

    Ok thats Great. But im stil confused where i must copy that script. im using blogspot. am i must copy thats script before </body> or before </head> on blogspot template?

  • Boris
    Replied on October 21, 2015 at 4:02 AM

    The script can be anywhere - you can place it before the ending </body> tag on your website.

    The script must only be on the same page where the source code of your form is used.

    Please let us know how it goes.