Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q420 How can I copy just just the letters and only one of each from one form field to another?

You are here: irt.org | FAQ | JavaScript | Form | 6 | Q420 [ previous next ]

Try:

<script language="JavaScript"><!--
function vet(form) {
    var temp = '', input = form.input.value, length = form.input.value.length ;

    form.output.value = '';

    for (var i=0; i<length; i++) {
        var letter = input.substring(i,i+1);
        var uppercase = letter.toUpperCase();
        if (uppercase >= 'A' && uppercase <= 'Z' && temp.indexOf(uppercase) == -1) {
            temp += uppercase;
            form.output.value += letter;
        }

    }
}
//--></script>

<form>
<input type="text" name="input">
<input type="button" value="Validate" onClick="vet(this.form)">
<input type="text" name="output">
</form>

©2018 Martin Webb