radio button make text field equal value of form field

Discussion in 'Javascript' started by mitch-co2, Feb 21, 2005.

  1. mitch-co2

    mitch-co2 Guest

    What I am trying to do is when someone clicks on the YES radio button I
    want the text field called MYTEXT to equal the text field named DATE.

    The below code works as long as I do NOT UN-COMMENT the NO radio
    button, once I do that it will not work.

    Any help would be greatly appreciated.

    Mitch



    <body>
    <script language="JavaScript"><!--
    function setField(what) {
    if (what.myTick.checked)
    what.myText.value = what.date.value;
    else
    what.myText.value = '';
    }
    //--></script>

    <form>
    <p>
    Yes <input name="myTick" type="radio" value="Yes"
    onClick="setField(this.form)">
    <!-- No <input name="myTick" type="radio" value="No"> -->
    </p>
    <p>sample date
    <input type="text" name="date" value="20050202">
    auto fill in
    <input type="text" name="myText">
    </p>
    </form>

    </body>
    mitch-co2, Feb 21, 2005
    #1
    1. Advertising

  2. mitch-co2

    McKirahan Guest

    "mitch-co2" <> wrote in message
    news:...
    > What I am trying to do is when someone clicks on the YES radio button I
    > want the text field called MYTEXT to equal the text field named DATE.
    >
    > The below code works as long as I do NOT UN-COMMENT the NO radio
    > button, once I do that it will not work.
    >
    > Any help would be greatly appreciated.
    >
    > Mitch
    >
    >
    >
    > <body>
    > <script language="JavaScript"><!--
    > function setField(what) {
    > if (what.myTick.checked)
    > what.myText.value = what.date.value;
    > else
    > what.myText.value = '';
    > }
    > //--></script>
    >
    > <form>
    > <p>
    > Yes <input name="myTick" type="radio" value="Yes"
    > onClick="setField(this.form)">
    > <!-- No <input name="myTick" type="radio" value="No"> -->
    > </p>
    > <p>sample date
    > <input type="text" name="date" value="20050202">
    > auto fill in
    > <input type="text" name="myText">
    > </p>
    > </form>
    >
    > </body>
    >


    Will this help? Watch for word-wrap.

    <html>
    <head>
    <title>RadioYes.htm</title>
    <script type="text/javascript">
    function setField(form,what) {
    (what == 1) ? form.myText.value = form.date.value : form.myText.value =
    "";
    }
    </script>
    </head>
    <body>
    <form>
    Yes <input name="myTick" type="radio" value="Yes"
    onClick="setField(this.form,1)">
    No <input name="myTick" type="radio" value="No"
    onClick="setField(this.form,0)">
    <br>sample date : &nbsp;
    <input type="text" name="date" value="20050202">
    <br>auto fill in : &nbsp;
    <input type="text" name="myText">
    </form>
    </body>
    </html>
    McKirahan, Feb 21, 2005
    #2
    1. Advertising

  3. mitch-co2

    mitch-co2 Guest

    McKirahan,

    Thank you very much for the help...it worked perfectly!

    Mitch



    McKirahan wrote:
    > "mitch-co2" <> wrote in message
    > news:...
    > > What I am trying to do is when someone clicks on the YES radio

    button I
    > > want the text field called MYTEXT to equal the text field named

    DATE.
    > >
    > > The below code works as long as I do NOT UN-COMMENT the NO radio
    > > button, once I do that it will not work.
    > >
    > > Any help would be greatly appreciated.
    > >
    > > Mitch
    > >
    > >
    > >
    > > <body>
    > > <script language="JavaScript"><!--
    > > function setField(what) {
    > > if (what.myTick.checked)
    > > what.myText.value = what.date.value;
    > > else
    > > what.myText.value = '';
    > > }
    > > //--></script>
    > >
    > > <form>
    > > <p>
    > > Yes <input name="myTick" type="radio" value="Yes"
    > > onClick="setField(this.form)">
    > > <!-- No <input name="myTick" type="radio" value="No"> -->
    > > </p>
    > > <p>sample date
    > > <input type="text" name="date" value="20050202">
    > > auto fill in
    > > <input type="text" name="myText">
    > > </p>
    > > </form>
    > >
    > > </body>
    > >

    >
    > Will this help? Watch for word-wrap.
    >
    > <html>
    > <head>
    > <title>RadioYes.htm</title>
    > <script type="text/javascript">
    > function setField(form,what) {
    > (what == 1) ? form.myText.value = form.date.value :

    form.myText.value =
    > "";
    > }
    > </script>
    > </head>
    > <body>
    > <form>
    > Yes <input name="myTick" type="radio" value="Yes"
    > onClick="setField(this.form,1)">
    > No <input name="myTick" type="radio" value="No"
    > onClick="setField(this.form,0)">
    > <br>sample date : &nbsp;
    > <input type="text" name="date" value="20050202">
    > <br>auto fill in : &nbsp;
    > <input type="text" name="myText">
    > </form>
    > </body>
    > </html>
    mitch-co2, Feb 22, 2005
    #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. Scott D Johnson
    Replies:
    1
    Views:
    1,064
    Scott D Johnson
    Sep 27, 2006
  2. tshad
    Replies:
    6
    Views:
    6,965
    Alexey Smirnov
    Nov 26, 2009
  3. Hiten
    Replies:
    1
    Views:
    620
    Vidar Petursson
    May 26, 2004
  4. Chuck
    Replies:
    0
    Views:
    260
    Chuck
    Nov 10, 2003
  5. PeeZee
    Replies:
    1
    Views:
    113
Loading...

Share This Page