PDA

View Full Version : How can I create leading zeroes in HTML or Javascripts


vthoi
02-09-2005, 03:15 AM
Hi

Can you please help me with this problem ?

When user enters input data less than the max length, how can I display leading zero on the screen ?

Thanks very much.

<html>
<head>
</head>
<body>
// --></script><script type="text/javascript">
function fold(o){ o.value=o.value.toUpperCase(); }
</script>
<form name="form1">
<table border="0" cellpadding="0" cellspacing="0" width="1000"
bordercolor="#000080">
<tr>
<td width="25%"><font size="2"><strong>Search Key</strong></font></td>
<td width="10%"><font size="3"><input type="text" size="14" maxlength="11" name="search_key"
onkeydown="fold(this)"
onblur="fold(this)"
onclick="fold(this)"></font></td>
</tr>
</form>
</body>
</html>

hemebond
02-09-2005, 04:16 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>51949</title>
</head>
<body>
<form name="form1">
<label for="search_key">Search Key</label>
<input id="search_key" name="search_key" type="text" size="14" maxlength="11" onkeydown="fold(this)" onblur="fill(this)" onclick="fold(this)">
</form>

<script type="text/javascript">
function fold(obj)
{
obj.value = obj.value.toUpperCase();
}

function fill(obj)
{
var txt = '';
for(var i = 0, size = (obj.getAttribute("maxlength") - obj.value.length); i < size; i++)
{
txt += '0';
}
obj.value = txt + obj.value;
}
</script>
</body>
</html>Not sure what you're trying to achieve.

vthoi
02-09-2005, 04:30 AM
Hi hemebond

Thanks very much for your help.

Vthoi