set input field from javascript.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: set input field from javascript.

  1. #1
    Zerg Guest

    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.

  2. #2
    Frederiek Guest

    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.



  3. #3
    Zerg Guest

    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center