Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SOS Newbie needs help!! SOS! Newbie needs Help!

    Lets see, here's my code:


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>

    <script type="text/javascript" >

    var flag ;
    var Digito ;
    var Operador

    function EscribeDigito(Digito)
    {
    window.document.form1.raultext.value=(Digito)

    var flag = true;
    return false;

    }

    function valTest()
    {
    window.alert("The value of flag is "+ flag);
    window.alert("The value of digito is "+ Digito);
    }

    //function Operator(Digito,Operador)
    //{ if (flag == true)
    // {
    // window.document.form1.raultext.value=(Digito+Operador);
    // }


    </script>

    </head>

    <body>

    <form name="form1" method="post" action="">
    <p>
    <input type="text" name="raultext">
    </p>
    <p>
    <input name="button1" type="submit" id="button1" value="1" onClick="EscribeDigito(1); return false;" >

    <input name="valueTest" type="submit" id="valueTest" value="valueTest" onClick="valTest();">

    <input name="multiply" type="submit" id="multiply" value="*" onClick=" Operator(Digito,*); return false;">
    </p>
    <p>
    <input name="button2" type="submit" id="button2" value="2" onClick="EscribeDigito(2); return false;" >
    </p>
    <p>
    <input name="button3" type="submit" id="button3" value="3" onClick="EscribeDigito(3); return false;" >
    </p>
    </form>

    </body>
    </html>


    The reason for the valTest function is that after running the Escribedigito function,by running the Onclick function, I am testing whether the flag and Digito values change.

    I'd like to make them change to flag = true and Digito = (To whatever button you onclick).

    I know here's a Global and Local variable issue, but is there a way I could modify the value of a global variable from a function??

    (I hope you understand what I mean as I suppose it's not difficult to tell that, yes I am a Newbie!)

  • #2
    New Coder
    Join Date
    Sep 2005
    Location
    New Zealand
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have had a quick look at your code and this may sort some of the problems or get you on the way to a solution.

    var Operador
    <input name="multiply" type="submit" id="multiply" value="*" onClick=" Operator(Digito,*); return false;">

    I think the "Operator" should be "Operador"

    Inside the function EscribeDigito you declare a local var flag. I guess you want this to be the global var flag, so you need to leave out the "var".

    In general, you should avoid global variables, they lead to confusion.

    Paul
    ScrypTik Javascript editor with built in syntax error checking

  • #3
    By@
    By@ is offline
    New Coder
    Join Date
    Sep 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •