toggle .value property ?

Discussion in 'Javascript' started by Jürgen Heyn, Feb 13, 2004.

  1. Jürgen Heyn

    Jürgen Heyn Guest

    Good morning,

    on form 2 input elements and 1 image are placed. The 1st (Index[0]) one is
    "hidden", the 2nd [Index[1]) is an empty textbox.
    When clicking the picture I would like to toogle a boolean value. (displayed
    in the textbox).
    The following function reacts correctly on the first click. Any further
    click as no effect (is returns "TRUE" in the textbox).
    Where is the mistake ? How can I solve the problem ?
    Thank you very much in advance.
    Best regards
    Juergen Heyn, Wilhelmshaven, Germany

    <script language="JavaScript">
    <!--

    function toggle()
    {
    if(document.forms[0].elements[0].value="yes")
    {
    document.forms[0].elements[1].value="TRUE";
    document.forms[0].elements[0].value="no";
    }
    else
    {
    document.forms[0].elements[1].value="FALSE";
    document.forms[0].elements[0].value="yes";
    }
    }

    // -->
    </script>

    <body>

    <form action="">
    <p>
    <input type="hidden" name="YesNo" value="yes">
    <input type="text" name="Textbox" size="20">
    <a href="#" onClick=toggle()>
    <img src="Button.gif" border="0" width="36" height="36">
    </p>
    </form>

    </body>
     
    Jürgen Heyn, Feb 13, 2004
    #1
    1. Advertising

  2. Jürgen Heyn

    Ivo Guest

    "Jürgen Heyn" <> wrote in message
    news:c0i7vj$17pudb$-berlin.de...
    (...)
    >
    > function toggle()
    > {
    > if(document.forms[0].elements[0].value="yes")
    > {
    > document.forms[0].elements[1].value="TRUE";
    > document.forms[0].elements[0].value="no";
    > }
    > else
    > {


    I suppose you mean
    if(document.forms[0].elements[0].value=="yes")
    with double "="
    Also note that "TRUE" between quotes is not a boolean, but a string.
    HTH
    Ivo
     
    Ivo, Feb 13, 2004
    #2
    1. Advertising

  3. Jürgen Heyn

    Jürgen Heyn Guest

    Hi Ivo,

    Thank you very much for the hint. This was actually my mistake.
    Coming from Visual Basic the double "==" was unknown.
    Thanks again !
    Regards
    Jürgen


    "Ivo" <> schrieb im Newsbeitrag
    news:402d013c$0$70746$...
    > "Jürgen Heyn" <> wrote in message
    > news:c0i7vj$17pudb$-berlin.de...
    > (...)
    > >
    > > function toggle()
    > > {
    > > if(document.forms[0].elements[0].value="yes")
    > > {
    > > document.forms[0].elements[1].value="TRUE";
    > > document.forms[0].elements[0].value="no";
    > > }
    > > else
    > > {

    >
    > I suppose you mean
    > if(document.forms[0].elements[0].value=="yes")
    > with double "="
    > Also note that "TRUE" between quotes is not a boolean, but a string.
    > HTH
    > Ivo
    >
    >
     
    Jürgen Heyn, Feb 13, 2004
    #3
  4. On Fri, 13 Feb 2004 17:43:59 +0100, Ivo <> wrote:

    > Also note that "TRUE" between quotes is not a boolean, but a string.


    Considering that the value property of form controls is of type string, do
    you really think it matters much?

    Mike

    --
    Michael Winter
    d (replace ".invalid" with ".uk" to reply)
     
    Michael Winter, Feb 13, 2004
    #4
    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. =?Utf-8?B?a2Q=?=

    How to toggle between window splits?

    =?Utf-8?B?a2Q=?=, May 2, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    466
    =?Utf-8?B?a2Q=?=
    May 2, 2005
  2. O.R.Senthil Kumaran
    Replies:
    3
    Views:
    1,003
    Eric Brunel
    Jul 5, 2007
  3. Nathan Sokalski
    Replies:
    25
    Views:
    1,477
    Nathan Sokalski
    Mar 4, 2010
  4. Dev_SH
    Replies:
    0
    Views:
    675
    Dev_SH
    Dec 30, 2010
  5. KJ
    Replies:
    0
    Views:
    152
Loading...

Share This Page