/    Sign up×
Community /Pin to ProfileBookmark

adding from a list to textfield

I am looking for a JavaScript that can do the fallowing

A list of number from 0 to 9

When someone click on the number above

It will show in the text field below

0 1 2 3 4 5 6 7 8 9

So if I click 3 and then 1 and then 5

[ 315-xxx-xxxx ]

Let me know where I can get some info on how to do this

Thanks

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsJul 07.2005 — [CODE]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
</head>

<body>

<table cellpadding="0" cellspacing="0" border="1">
<tr>
<td width=20 align=center onclick="AddNu(0);" >0</td>
<td width=20 align=center onclick="AddNu(1);" >1</td>
<td width=20 align=center onclick="AddNu(2);" >2</td>
<td width=20 align=center onclick="AddNu(3);" >3</td>
<td width=20 align=center onclick="AddNu(4);" >4</td>
<td width=20 align=center onclick="AddNu(5);" >5</td>
<td width=20 align=center onclick="AddNu(6);" >6</td>
<td width=20 align=center onclick="AddNu(7);" >7</td>
<td width=20 align=center onclick="AddNu(8);" >8</td>
<td width=20 align=center onclick="AddNu(9);" >9</td>
</tr>
</table>
<br>
<br>
<input id="fred" size="10" value="Phone Number" onkeyup="javascript:f20_FormatNumber(this,'~~~-~~~-~~~');" >
<script language="JavaScript" type="text/javascript">
<!--
function AddNu(n){
obj=document.getElementById('fred');
obj.value+=n;
f20_FormatNumber(obj,'~~~-~~~-~~~');
}

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--
// Form Compendium f20 (12-05-2005)
// Format Number
// by Vic Phillips http://www.vicsjavascripts.org.uk

// Format a number, such as a phone number as required

// Application Notes

// The format is specified as a string
// and passed to the function 'f20_FormatNumber()' on the onkeyup event of a text box
// e.g.
// <input name="" size="10" value="Phone Number" onkeyup="javascript:f20_FormatNumber(this,'(~~~) ~~~~~~');" >

// The sting charactors '~' will be replaced by the numbers typed in the text box

// There can be any number of applications on a page each with a unique format

// All variable, function etc. names are prefixed with 'f20_' to minimise conflicts with other JavaScripts

// Customising Variables
var f20_TypingColor='blue';
var f20_CompleteColor='black';
var f20_WarningColor='RED';

// Functional Code

// NO NEED to Change
var f20_Temp,f20_Lgth;
var f20_re=/D/g;
var f20_re1=/~/g;

function f20_FormatNumber(obj,tem){
obj.style.color=f20_TypingColor;
f20_re = /D/g;
obj.value=obj.value.replace(f20_re,'');
f20_Temp=tem;
for (f20_0=0;f20_0<obj.value.length;f20_0++){
f20_Lgth=f20_Temp.indexOf('~');
f20_Temp=f20_Temp.replace('~',obj.value.charAt(f20_0));
}
if (obj.value.length>0&&(f20_Lgth<0||obj.value.length==tem.match(f20_re1).length)){
obj.value=f20_Temp.substring(0,tem.length);
obj.style.color=f20_CompleteColor;
}
if (f20_Lgth>=0&&obj.value.length>0){
obj.value=f20_Temp.substring(0,f20_Lgth+1);
}
obj.lgth=tem.length;
obj.onblur=function(){
this.style.color=f20_CompleteColor;
if (this.value.length<obj.lgth){
if (this.value.length<1){ this.value='Please Complete'; }
this.style.color=f20_WarningColor;
alert('Please Complete then '+f20_WarningColor+'nField');
}
}
obj.onfocus=function(){
this.style.color=f20_TypingColor;
}

}

//-->
</script>

</body>

</html>
[/CODE]
×

Success!

Help @jorgepino spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...