Split String (SecretWord)
by Christopher O
HTML
<form>
<label>Secret Word: </label><input name="crs" id="crs" type="text" value="bingoplayers" /> <input type="text" value="" id="swnum" style="border:0; background-color:#efeffa; width:50px" title="Use dots: 1.2.3" />
<label> = </label><input value="" id="swuse" readonly="readonly" style="border:0; background-color:#efeffa; width:30px" />
<br />
</form>
JavaScript
$(document).on('keyup change', '#swnum', function(){
var value = $(this).val();
if ( value.length > 0 ){
var swchars = $('#crs').val().split('');
var swnums = value.split(/\./);
var outty = '';
swnums.forEach(function(entry) {
if ( entry.length > 0 && swchars[entry - 1] ){
outty = outty.concat( swchars[entry - 1] );
}
});
$('#swuse').val( outty );
}else{
$('#swuse').val( '' );
}
});