0

I tried looking around for an answer on here but couldn't find anything that resembles this problem, but what I am trying to do is get an input cell to format itself after a user inputs a number i.e. "100" will format to "100%" but that never happens.

When the onchange event fires it works and processes the input just fine but when it comes time to change the attribute "value" of the input field nothing happens. Why is this?

In my javascript I have

<input onchange='update();' ....

The update method is called but when it comes to this line

element.setAttribute(attr, value);

Nothing seems to happen. Does the focus of the input box need to be removed before changing the value of the input box?

1
  • So you want an input field [ 100 ] to convert to [ 100% ] ? use element.value = element.value + '%' Commented Jun 23, 2014 at 20:00

2 Answers 2

1

Just call .value

element.value = value;
Sign up to request clarification or add additional context in comments.

3 Comments

Yeah, no reason to be using setAttribute here
Thank you! I didn't know you could do that. I am using an IDE that shows methods or variables as you type and only setAttribute shows up, not .value Thanks again though, I feel silly now. :/
@Cian -- No worries - if the IDE isn't specifically designed for JavaScript hint detection then assume there's always more methods available
0

Try

<input onchange='update(this);'

and

function update(element) {
element.value=value;

You don't seem to be telling it which element is being referred to (unless you call it elsewhere in your function).

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.