Skip to main content
deleted 20 characters in body
Source Link
Mehul Mistri
  • 15.1k
  • 14
  • 72
  • 96

A "while" loop should make this easy enough.

function formatLength(a) {
    var num = document.getElementById(a)
    while (num.value.length < 4) {
        num.value = '0' + num.value
    }
}

That would loop through until the length of the num value reached 4 digits (assuming you have passed in the id of the number element as an argument)

I hope this helps.

A "while" loop should make this easy enough.

function formatLength(a) {
    var num = document.getElementById(a)
    while (num.value.length < 4) {
        num.value = '0' + num.value
    }
}

That would loop through until the length of the num value reached 4 digits (assuming you have passed in the id of the number element as an argument)

I hope this helps.

A "while" loop should make this easy enough.

function formatLength(a) {
    var num = document.getElementById(a)
    while (num.value.length < 4) {
        num.value = '0' + num.value
    }
}

That would loop through until the length of the num value reached 4 digits (assuming you have passed in the id of the number element as an argument)

Formatting.
Source Link
animuson
  • 54.9k
  • 28
  • 142
  • 150

A "while" loop should make this easy enough.

function formatLength(a) {
  var num = document.getElementById(a)
  while (num.value.length < 4) {
    num.value = '0' + num.value
}

function formatLength(a) {
    var num = document.getElementById(a)
    while (num.value.length < 4) {
        num.value = '0' + num.value
    }
}

That would loop through until the length of the num value reached 4 digits (assuming you have passed in the id of the number element as an argument)

I hope this helps.

A "while" loop should make this easy enough.

function formatLength(a) {
  var num = document.getElementById(a)
  while (num.value.length < 4) {
    num.value = '0' + num.value
}

That would loop through until the length of the num value reached 4 digits (assuming you have passed in the id of the number element as an argument)

I hope this helps.

A "while" loop should make this easy enough.

function formatLength(a) {
    var num = document.getElementById(a)
    while (num.value.length < 4) {
        num.value = '0' + num.value
    }
}

That would loop through until the length of the num value reached 4 digits (assuming you have passed in the id of the number element as an argument)

I hope this helps.

Source Link

A "while" loop should make this easy enough.

function formatLength(a) {
  var num = document.getElementById(a)
  while (num.value.length < 4) {
    num.value = '0' + num.value
}

That would loop through until the length of the num value reached 4 digits (assuming you have passed in the id of the number element as an argument)

I hope this helps.