-
set input field from javascript.
hi,
i have a form within a <DIV>.
this is the code.
<DIV ID="my_div" CLASS=in_textfield>
<FORM name="myform">
<Input type=text name="my_tf" value="">
</FORM>
</DIV>
i want to set the value in the text box to "abc" from a javascript function.
function test()
{
document.forms['myform'].my_tf.value = "abc" ;
}
and i got this error :
document.forms.myform has no properties.
why ? pls help me.
thank u.
-
Re: set input field from javascript.
NS returns this error as you have to point to the field by its full path in
the div. You can't access the field directly.
Use:
document.my_div.document.myform.my_tf.value = "abc";
But be sure to have set the position of the div to absolute or relative in
CSS. And you can only execute the function when the div object exists (the
page has rendered), eg from an onload in the body tag or a click on some
kind of link.
cya
Frederiek
"Zerg" <chankh@fsl.fujitsu.com.sg> wrote:
>
>hi,
>i have a form within a <DIV>.
>this is the code.
><DIV ID="my_div" CLASS=in_textfield>
> <FORM name="myform">
> <Input type=text name="my_tf" value="">
> </FORM>
></DIV>
>
>i want to set the value in the text box to "abc" from a javascript function.
>
>function test()
>{
> document.forms['myform'].my_tf.value = "abc" ;
>}
>
>and i got this error :
>document.forms.myform has no properties.
>
>why ? pls help me.
>
>thank u.
-
Re: set input field from javascript.
hi Frederiek,
good answer. it helps. thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|