DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  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


Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links