cuconsortium
asked on
Java Script Function
Dear all,
Let's say I have a java script function as follow:
<script type="text/javascript">
function format(num)
{
bluh
bluh
bluh
}
</script>
I'd like to mask an input text field data. How do I call this format(num) java script function in the HTML form?
</head>
<body>
<form name="DataEntryForm">
<input name="phone" type="text" id="phone" onChange="" /></form>
</body>
</html>
Thank you!!
Let's say I have a java script function as follow:
<script type="text/javascript">
function format(num)
{
bluh
bluh
bluh
}
</script>
I'd like to mask an input text field data. How do I call this format(num) java script function in the HTML form?
</head>
<body>
<form name="DataEntryForm">
<input name="phone" type="text" id="phone" onChange="" /></form>
</body>
</html>
Thank you!!
try here they have some input masks that you can download for free http://www.webresourcesdep ot.com/jav ascript-in put-masks/
Hi,
try this:
that will trigger your function, everytime the inputfield looses its focus. If you want to trigger it everytime the value changes, use the onkeyup-event instead of onchange.
try this:
function format()
{
var num = document.getElementById('phone').value;
bluh
bluh
bluh
}
<input name="phone" type="text" id="phone" onchange="format();" /></form>
that will trigger your function, everytime the inputfield looses its focus. If you want to trigger it everytime the value changes, use the onkeyup-event instead of onchange.
ASKER
Hi Dr_Pitter,
I have several text fields that need to apply this mask. From what you described, that means I'll need to build one function for each text field. Is there a better way?
Thank you!
I have several text fields that need to apply this mask. From what you described, that means I'll need to build one function for each text field. Is there a better way?
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hi cuconsortium,
You can set the formatting to all inputs with the same classname after loading the page by using the window.onload event.
Given you have these inputs where to set the formatting:
<input name="phone" type="text" id="phone" class="num_format" />
<input name="phone1" type="text" id="phone1" class="num_format" />
<input name="phone2" type="text" id="phone2" class="num_format" />
<input name="phone3" type="text" id="phone3" class="num_format" />
Create these javascript functions:
<script type="text/javascript">
function format(num) {
bluh
bluh
bluh
}
function setFormat() {
var inputs = document.getElementsByClas sName('num _format');
for( var x=0; x<inputs.length; x++ ) {
//set the formatting
inputs[x].onchange = function() {
var num = this.value;
format(num);
}
}
}
window.onload = setFormat;
</script>
With that, all settings of onchange event to inputs with "num_format" class will be done after the loading of page.
Hope that helps... Have a good day... :)
You can set the formatting to all inputs with the same classname after loading the page by using the window.onload event.
Given you have these inputs where to set the formatting:
<input name="phone" type="text" id="phone" class="num_format" />
<input name="phone1" type="text" id="phone1" class="num_format" />
<input name="phone2" type="text" id="phone2" class="num_format" />
<input name="phone3" type="text" id="phone3" class="num_format" />
Create these javascript functions:
<script type="text/javascript">
function format(num) {
bluh
bluh
bluh
}
function setFormat() {
var inputs = document.getElementsByClas
for( var x=0; x<inputs.length; x++ ) {
//set the formatting
inputs[x].onchange = function() {
var num = this.value;
format(num);
}
}
}
window.onload = setFormat;
</script>
With that, all settings of onchange event to inputs with "num_format" class will be done after the loading of page.
Hope that helps... Have a good day... :)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.