Nieuw lid |
|
Hallo,
Wat mankeert aan volgend script ?
Het aftrekken verloopt perfect, bij het optellen wordt de waarde geconcateneerd aan de string.
<html>
<head>
<script type="text/javascript"><!--
Number.prototype.numToHex = function(){
return this.toString(16).toUpperCase();
}
String.prototype.hexToNum = function(){
return parseInt(this);
}
function init(){
var rescolor="0xffffff".hexToNum();
set_cookie(rescolor);
document.f1.outputhex.value=rescolor.numToHex();
document.f1.outputnum.value=rescolor;
}
function setColor(arg){
rescolor = csearch("color");
switch(arg){
case -1:
rescolor = (rescolor - "0x010000".hexToNum());
break;
case 1:
rescolor = (rescolor + "0x010000".hexToNum());
break;
case -2:
rescolor = (rescolor - "0x000100".hexToNum());
break;
case 2:
rescolor = (rescolor + "0x000100".hexToNum());
break;
case -3:
rescolor = (rescolor - "0x000001".hexToNum());
break;
case 3:
rescolor = (rescolor + "0x000001".hexToNum());
break;
default:
break;
}
set_cookie(rescolor);
document.f1.outputnum.value=rescolor;
document.f1.outputhex.value=rescolor.numToHex();
}
function set_cookie(rescolor){
var exp = new Date();
exp.setMonth(exp.getMonth() + 1);
document.cookie = "color = "+rescolor+" ;expires="+exp+" ;path=/";
}
function csearch(naam) {
var str = document.cookie;
var zstr = naam + "=";
var start = str.indexOf(zstr, 0);
if(start == -1) {
return false;
} else {
start += zstr.length;
var eind = str.indexOf(";", start);
if(eind == -1) eind = str.length;
return unescape(str.substring(start, eind));
}
}
--></script>
</head>
<body onload="init()">
<form name="f1" method=post">
<table>
<tr>
<td><input type="button" value="sub" name="r-" onClick="setColor(-1)" ></td>
<td>Red</td>
<td><input type="button" value="add" name="r+" onClick="setColor(1)" ></td>
</tr>
<tr>
<td><input type="button" value="sub" name="g-" onClick="setColor(-2)"></td>
<td>Green</td>
<td><input type="button" value="add" name="g+" onClick="setColor(2)"></td>
</tr>
<tr>
<td><input type="button" value="sub" name="b-" onClick="setColor(-3)"></td>
<td>Blue</td>
<td><input type="button" value="add" name="b+" onClick="setColor(3)"></td>
</tr>
</table>
<input type="text" name="outputhex" size="9"><br>
<input type="text" name="outputnum" size="19">
</form>
</body>
</html>
<html> <head> <script type="text/javascript"><!-- Number.prototype.numToHex = function(){ return this.toString(16).toUpperCase(); } String.prototype.hexToNum = function(){ return parseInt(this); } function init(){ var rescolor="0xffffff".hexToNum(); set_cookie(rescolor); document.f1.outputhex.value=rescolor.numToHex(); document.f1.outputnum.value=rescolor; } function setColor(arg){ rescolor = csearch("color"); switch(arg){ case -1: rescolor = (rescolor - "0x010000".hexToNum()); break; case 1: rescolor = (rescolor + "0x010000".hexToNum()); break; case -2: rescolor = (rescolor - "0x000100".hexToNum()); break; case 2: rescolor = (rescolor + "0x000100".hexToNum()); break; case -3: rescolor = (rescolor - "0x000001".hexToNum()); break; case 3: rescolor = (rescolor + "0x000001".hexToNum()); break; default: break; } set_cookie(rescolor); document.f1.outputnum.value=rescolor; document.f1.outputhex.value=rescolor.numToHex(); } function set_cookie(rescolor){ exp.setMonth (exp.getMonth () + 1); document .cookie = "color = "+rescolor +" ;expires="+exp+" ;path=/";} function csearch(naam) { var str = document.cookie; var zstr = naam + "="; var start = str.indexOf(zstr, 0); if(start == -1) { return false; } else { start += zstr.length; var eind = str.indexOf(";", start); if(eind == -1) eind = str.length; return unescape(str.substring(start, eind)); } } --></script> </head> <body onload="init()"> <form name="f1" method=post"> <table> <tr> <td><input type="button" value="sub" name="r-" onClick="setColor(-1)" ></td> <td>Red</td> <td><input type="button" value="add" name="r+" onClick="setColor(1)" ></td> </tr> <tr> <td><input type="button" value="sub" name="g-" onClick="setColor(-2)"></td> <td>Green</td> <td><input type="button" value="add" name="g+" onClick="setColor(2)"></td> </tr> <tr> <td><input type="button" value="sub" name="b-" onClick="setColor(-3)"></td> <td>Blue</td> <td><input type="button" value="add" name="b+" onClick="setColor(3)"></td> </tr> </table> <input type="text" name="outputhex" size="9"><br> <input type="text" name="outputnum" size="19"> </form> </body> </html>
Kan iemand helpen ???
|