/    Sign up×
Community /Pin to ProfileBookmark

List menu to input text

Hi. This is my first post in this page, and its great.

I want to input a value selected from a list menu to an input text.

And split n numbers with “-” every 3 numbers.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERMar 05.2008 — [code=php]
<select name='SList' onChange="document.getElementById('TBox').value=this.value">
<option value="0">Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>

Option selected:
<input type="text" id="TBox" value="">
[/code]

Coded on the fly (meaning: not tested)

Post back if you have problems as it should work. ?

For the '-' insert after 3 characters.

1. Look at this forum (search) for insertion of ',' and substitute the '-' character

2. Will probably use a 'regex' expression to do it.

3. I've seen it done on this forum, but cannot remember where.
Copy linkTweet thisAlerts:
@Ay__351_eMar 05.2008 — <i>
</i>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta content="text/html; charset=UTF-8"
http-equiv="content-type"&gt;
&lt;title&gt;&lt;/title&gt;
&lt;style type="text/css"&gt;
.myfield { display:none;}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
el=function(myid){return document.getElementById(myid);}
yessar =function(bu){
el('inp').value= bu.value.split('').reverse().join('').replace(/(d{3})(?=d)/g, '$1-').split('').reverse().join('');
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;select id="sel" onchange="yessar(this)"&gt;
&lt;option value=""&gt;choose&lt;/option&gt;
&lt;option value="11111"&gt;11111&lt;/option&gt;
&lt;option value="222222"&gt;222222&lt;/option&gt;
&lt;option value="3333"&gt;3333&lt;/option&gt;
&lt;option value="444444"&gt;444444&lt;/option&gt;
&lt;option value="5555555"&gt;5555555&lt;/option&gt;
&lt;/select&gt;

&lt;input type="text" id="inp"&gt;

&lt;/body&gt;
&lt;/html&gt;


http://www.sitepoint.com/forums/showthread.php?t=475713
×

Success!

Help @yasser 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.18,
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,
)...