1

I have some elements inside an iframe with an onclick event associated, something like:

<iframe>
 ... 
    <input type="text" onclick="somefunction(this)"/>
 ...
</iframe>

In the function called I try to change the value of the input, nothing special:

{
...
foo.value = "changed!"
...
}

At this point I can see in firebug that the value has changed but when the function finish the value doesn't change at all.

The same kind of thing with an onmouseover seems to work.

Any ideas?

Thanks.

Edit: Change code mistake

2 Answers 2

1

'this' means different things in the different contexts

Given:

<input type="text" onclick="somefunction(this)"/>

'this' is the input (since it is called as myInput.onclick())

But:

function someFunction(foo) {
    this.value;
}

You are calling as:

someFunction(myInput)

which is the same as

window.someFunction(myInput)

So in that context, 'this' is the window object.

Use 'foo' instead (since that is the argument name in the function declaration).

Sign up to request clarification or add additional context in comments.

1 Comment

You are completely right, but I made that mistake while writing the question here, is correct in the actual code.
0

Value is not defined for an iframe tag. In Javascript, the "value" member is merely added to the object when set, but of course not taken into account by the navigator.

For setting content (this is also the case for div), you should use :

this.innerHTML = "Changed!";

or

this.innerText = "Changed!";

2 Comments

The question is about an input inside an iframe, not the iframe itself (although, frankly, the iframe is a red herring).
Thank you. But I actually want to change the input inside the iframe, not the iframe itself.

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.