dynamically set textboxes

Discussion in 'Javascript' started by Ben Dover - Mental Patient 0057, Aug 28, 2003.

  1. i want to be able to dynamically set different text boxes depending on
    the button pressed.


    i was hoping obj() can "become" object "aaa" or "bbb", but it's not
    working.

    function clearBox(inputobject) {
    var obj=(inputobject);
    document.main.ojb().value="hello";
    document.main.aaa.focus();
    }


    ----------------
    <form name="main">
    <input type="text" value="aaa" name="boxaaa">
    <input type="text" value="bbb" name="boxbbb">
    <input type="button" value="clickme" onclick="clearBox(aaa)">
    <input type="button" value="clickme" onclick="clearBox(bbb)">
    </form>
     
    Ben Dover - Mental Patient 0057, Aug 28, 2003
    #1
    1. Advertising

  2. Ben Dover - Mental Patient 0057 <-Hospital.com> writes:

    > i want to be able to dynamically set different text boxes depending on
    > the button pressed.


    > i was hoping obj() can "become" object "aaa" or "bbb", but it's not
    > working.
    >
    > function clearBox(inputobject) {
    > var obj=(inputobject);
    > document.main.ojb().value="hello";


    From the FAQ <URL:http://jibbering.com/faq/#FAQ4_39>

    document.forms['main'].elements[inputobject].value="hello";

    (I prefer to always use the forms and elements collections)

    This also requires that the remaining code is correct :

    > <input type="text" value="aaa" name="boxaaa">
    > <input type="text" value="bbb" name="boxbbb">
    > <input type="button" value="clickme" onclick="clearBox(aaa)">

    onclick="clearBox('aaa')"
    You want to send a string, not the value of the possibly non-existing
    global variable called "aaa".

    > <input type="button" value="clickme" onclick="clearBox(bbb)">


    Ditto here.

    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Aug 28, 2003
    #2
    1. Advertising

  3. just want to share with everyone what I put together:
    in the head:

    function clearBox(inputobject) {
    var obj=(inputobject);
    document.main[inputobject].value="";
    document.main[inputobject].focus();
    }


    in the body:
    <form name="main" >
    <INPUT TYPE="TEXT" VALUE="helloworld" NAME="login">
    <a href="#" onclick="clearBox('login');">clear login</a>

    <INPUT TYPE="TEXT" VALUE="helloworld" NAME="password">
    <a href="#" onclick="clearBox('password');">clear password</a>

    etc...
    </form>


    have fun folks!

    Lasse Reichstein Nielsen wrote:
    >
    > Ben Dover - Mental Patient 0057 <-Hospital.com> writes:
    >
    > > i want to be able to dynamically set different text boxes depending on
    > > the button pressed.

    >
    > > i was hoping obj() can "become" object "aaa" or "bbb", but it's not
    > > working.
    > >
    > > function clearBox(inputobject) {
    > > var obj=(inputobject);
    > > document.main.ojb().value="hello";

    >
    > From the FAQ <URL:http://jibbering.com/faq/#FAQ4_39>
    >
    > document.forms['main'].elements[inputobject].value="hello";
    >
    > (I prefer to always use the forms and elements collections)
    >
    > This also requires that the remaining code is correct :
    >
    > > <input type="text" value="aaa" name="boxaaa">
    > > <input type="text" value="bbb" name="boxbbb">
    > > <input type="button" value="clickme" onclick="clearBox(aaa)">

    > onclick="clearBox('aaa')"
    > You want to send a string, not the value of the possibly non-existing
    > global variable called "aaa".
    >
    > > <input type="button" value="clickme" onclick="clearBox(bbb)">

    >
    > Ditto here.
    >
    > /L
    > --
    > Lasse Reichstein Nielsen -
    > Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    > 'Faith without judgement merely degrades the spirit divine.'
     
    Ben Dover - Mental Patient 0057, Aug 28, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Forconi Boris via .NET 247

    TextBoxes created dynamically : How to store data?

    Forconi Boris via .NET 247, Jun 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    382
    Trevor Benedict R
    Jun 18, 2004
  2. Tony
    Replies:
    5
    Views:
    374
    Jeff Louie
    Jun 27, 2004
  3. Charith Jayasundara via .NET 247

    How to use custom validators for dynamically genrated textboxes

    Charith Jayasundara via .NET 247, Mar 23, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    421
    Brock Allen
    Mar 23, 2005
  4. SD
    Replies:
    3
    Views:
    457
    =?Utf-8?B?S2V6emE=?=
    Jun 23, 2005
  5. RC
    Replies:
    1
    Views:
    590
    Teemu Keiski
    Jun 7, 2005
Loading...

Share This Page