Text box added using javascript doesnot respond as expected to the js attached to it.

Posted by Mallika Iyer on Stack Overflow See other posts from Stack Overflow or by Mallika Iyer
Published on 2010-06-03T21:11:12Z Indexed on 2010/06/03 21:14 UTC
Read the original article Hit count: 285

Filed under:
|
|

Hello, I am adding a text box using javascript:

This is what is generated:

       <dd id="text3-element" style="width: 350px;">
            <input type="text" size="50" id="text3" name="text3" onblur="return getFieldValue(this.id);" value="">
       </dd>

This is what is present in the getFieldValue function:

            function getFieldValue(id){

                var elem = document.getElementById(id);
                alert(elem.value);
                return false;
            }

I'm trying to get the value of the field added using javascript when the value of the filed changes.

However, I keep getting the value as 'undefined', in spite of entering text into the newly added text box.

This does not happen if the form already has a text box to begin with - i.e., if a text box is not being added via a js function.

Anything missing / look wrong here?

Thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript