1

I'm trying to create an autofill function. I'm using a select list, and based on option selected, some textboxes gets values put into them. The only problem is that I can't get extended ASCII-characters into a textbox with the function I'm using.

JS:

function fillContact() {
    var contact = document.getElementById('contact'),
        namebox = document.getElementById('namebox');

    if (contact.value === 'Bjorn') {
        namebox.value = 'Bj' + String.fromCharCode(148) + 'rn';
    }
    else if (contact.value === 'Tommy') {
        namebox.value = 'Tommy';
    }
}

HTML:

<select id='contact' onchange='fillContact();'>
   <option selected>-Choose contact-</option>
   <option value='Bjorn'>Bjorn</option>
   <option value='Tommy'>Tommy</option>
</select>

Name: <input type='textbox' id='namebox'>

String.fromCharCode() just doesn't encompass ASCII-character 148 (ö), that I want to put into a textbox. Any other String-function that can make it work? Something like String.getExtendedCharCode(148), or equivalent?

Note that other characters up to 128 works, and that contact 'Tommy' works.

2
  • The best option is to use UTF-8 instead of extended ASCII Commented Jul 1, 2015 at 12:52
  • JavaScript uses Unicode/UTF-16. Your question seems to be based on a misunderstanding of what ASCII means and what "extended ASCII" doesn't mean. Regardless, they aren't relevant. Commented Jul 1, 2015 at 22:57

1 Answer 1

1
namebox.value = 'Bj' + "\xF6" + 'rn';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.