...

View Full Version : SOS Newbie needs help!! SOS! Newbie needs Help!



Palomares
09-24-2005, 09:20 PM
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!)

scrypter
09-25-2005, 12:13 PM
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

By@
09-25-2005, 12:24 PM
I suggest reading this. (http://www.codingforums.com/showthread.php?t=2090)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum