webForumDet fria alternativet

function StabilareKurser()

3 svar · 202 visningar · startad av jenicpunktnu

jenicpunktnuMedlem sedan juni 200343 inlägg
#1

Tjena!

Sitter och "leker" lite med ett script jag modifierat lite, men de vill sej ej riktigt...som jag tänkt mig

Dvs Functionen StabilareKurs, redovisar ej det värde eller den funktionen jag önskat att den hade gjort.
(1)
Vad är det som gör att den en vill arbeta som jag vill att den skall?

Jag har tilldelat StabilareKurs[x] värdet av price[x] i slutet av koden. så att den skall minnas detta värde och ta det med sig till dag 2. Men detta vill sig ej...och kan dessvärre ej förstå varför.

StabilareKurs[x] = price[x];

(2)
Det andra jag undar över, är hur får jag bort "framsen" runt de olika rutorna som sedan de olika looperna skrivs ut i, dvs aktie namnet och liknande.
I själva <table ID="Table1" > tabellen så finns det inga frams runt, utan dessa ligger runt <option>.

För att kanske enklare se koden finns den på
AktieKungen

[kod]
<script language="JavaScript" type="text/javascript">

var x;
var cash = 500;
var daysleft = 32;

Aktier = ["Ericsson","Framfab","Scandia","ABB","Telia","Volvo","Atlas Copco","WM-Data","Nokia","Nordea","Switchcore","Investor","Icon", "Astrazeneca", "SCA", "SKF", "Sandvik", "Electrolux", "Skanska", "Swedish Match"]
setprices = [9.23,2,23,30,33,174,196,12,137,40,2,61,2,355,282,229,209,155,45,60]
price = new Array(20)
yourAktier = new Array(20)
yourprice = new Array(20)
quants = new Array(20)
AktieMin = new Array (20)
AktieMax = new Array (20)
StabilareKurs = new Array (20)

var quant;
for (x = 0; x < 20; x++){
yourAktier[x] = "";
yourprice[x] = ".";
quants[x] = "";
price[x]= ".";
AktieMin[x] = 9999999;
AktieMax[x] = 0;
StabilareKurs[x] = ".";
}

function calcmax(p){
var mp
var max = sAvail - sLeft;
for (x = 0; x <= max; x++){
mp = p * x;
if ((mp >= cash) || (x == max)){
return x;
}
}
}

function StabilareKurser()
{
for (x = 0; x < 20; x++)
{
if (StabilareKurs[x] > 0)
{
setprices[x] = StabilareKurs[x];
}
}
}

function MoreAktier()
{
x = 30000;
var x2 = confirm("Vill du köpa en portfölj med 100 nya aktie platser för " + Currency(x) + "?");
if ((x2 == true) && (cash >= x))
{
cash = cash - Number(x);
sAvail = Number(sAvail) + 100;
alert("Du har just investerat i 100 ny platser!");
}
else if ((x2 == true) && (cash < x))
{
alert("Du har dessvärre ej råd...");
}
}

function EvenMoreAktier()
{
x = 250000;
var x2 = confirm("Vill du köpa en portfölj med 1000 nya aktie platser för " + Currency(x) + "?");
if ((x2 == true) && (cash >= x))
{
cash = cash - Number(x);
sAvail = Number(sAvail) + 1000;
alert("Du har just investerat i 1000 ny platser!");
}
else if ((x2 == true) && (cash < x))
{
alert("Du har dessvärre ej råd...");
}
}

function TenKMoreAktier()
{
x = 2500000;
var x2 = confirm("Vill du köpa en portfölj med 10000 nya aktie platser för " + Currency(x) + "?");
if ((x2 == true) && (cash >= x))
{
cash = cash - Number(x);
sAvail = Number(sAvail) + 10000;
alert("Du har just investerat i 10000 ny platser!");
}
else if ((x2 == true) && (cash < x))
{
alert("Du har dessvärre ej råd...");
}
}

function showyours()
{
for (x = 0; x < 20; x++)
{
AktieForm.AktierPrice.options[x].text = Currency(yourprice[x]);
{
if (quants[x] > 0)
{
AktieForm.AktierYouHave.options[x].text = quants[x] + " st " + yourAktier[x];
}
else
{
AktieForm.AktierYouHave.options[x].text = quants[x] + " - " + yourAktier[x];
}
}
}
}

function MaxMin()
{
for (x = 0; x < 20; x++) {
var min;
var max;

      if(setprices\[x\] \> price\[x\]) { 
           max = setprices\[x\]; 
           min = price\[x\]; 
      } else { 
           max = price\[x\]; 
           min = setprices\[x\]; 
      } 

      if(min \< AktieMin\[x\]) { 
           AktieMin\[x\] = min; 
      } 
      
      if(max \> AktieMax\[x\]) { 
           AktieMax\[x\] = max; 
      } 
      AktieForm.AktieKursMax.options\[x\].text = Currency(AktieMax\[x\]); 
      AktieForm.AktieKursMin.options\[x\].text = Currency(AktieMin\[x\]); 
 } 

}

function sellit(){
var sel = AktieForm.AktierYouHave.selectedIndex;
if (sel == -1) {
alert("Du måste välja en aktie först.");
return;
}
quant = prompt("Hur många " + Aktier[sel] + "aktier vill du sälja?", quants[sel]);
if (quant == null) return;
if (quant < 0) {
alert("KOM IGEN NU...du kan ej sälja ett antal som ej existerar");
return;
}
if ((quants[sel] - quant) >= 0){
quants[sel] = Number(quants[sel]) - Number(quant);
cash = cash + price[sel] * Number(quant);
AktieForm.money.value = Currency(cash);
sLeft = Number(sLeft) - Number(quant);
AktieForm.spaceAvail.value = sAvail - 1;
AktieForm.spaceLeft.value = sLeft;
if (Number(quants[sel]) == 0){
yourAktier[sel] = "";
yourprice[sel] = ".";
quants[sel] = "";
}
showyours();
MaxMin();
AktieForm.AktierForSale.selectedIndex = -1;
AktieForm.AktiePrices.selectedIndex = -1;
AktieForm.AktierYouHave.selectedIndex = -1;
AktieForm.AktierPrice.selectedIndex = -1;
AktieForm.AktieKursMax.selectedIndex = -1;
AktieForm.AktieKursMin.selectedIndex = -1;
}
}

function buyit(){
var sel = AktieForm.AktierForSale.selectedIndex;
if (sel == -1) {
alert("Du måste välja en aktie först.");
return;
}
quant = prompt("Hur många " + Aktier[sel] + " vill du ha?", calcmax(price[sel]) - 1);
if (quant == null) return;
if (quant < 0) {
alert("KOM IGEN NU...du kan ej sälja ett antal som ej existerar...");
return; }
if (quant == 0) return;
if (((price[sel] * Number(quant)) <= cash) && ((Number(sLeft) + Number(quant)) <= Number(sAvail) - 1)){
quants[sel] = Number(quants[sel]) + Number(quant);
yourAktier[sel] = Aktier[sel];
yourprice[sel] = price[sel];
cash = cash - price[sel] * Number(quant);
sLeft = Number(sLeft) + Number(quant);
AktieForm.spaceAvail.value = sAvail - 1;
AktieForm.spaceLeft.value = sLeft;
showyours();
MaxMin();
AktieForm.money.value = Currency(cash);
AktieForm.AktierForSale.selectedIndex = -1;
AktieForm.AktiePrices.selectedIndex = -1;
AktieForm.AktierYouHave.selectedIndex = -1;
AktieForm.AktierPrice.selectedIndex = -1;
AktieForm.AktieKursMax.selectedIndex = -1;
AktieForm.AktieKursMin.selectedIndex = -1;
}else if ((quant > 0) && (cash < price[sel] * quant)){
alert("Du har ej tillräckligt med pengar");
return;
}
else {
alert("Det finns ej plats för detta");
return;
}
}

function RefreshSale() {
for (x = 0; x < 20; x++){
if ((x == 0) || (x == 1) || (x == 9) || (x == 10) || (x == 12)){
price[x] = setprices[x] * random(5)}
else if(x == 11) {price[x] = setprices[x] * random(2)}
else if(x == 8) {price[x] = setprices[x] * random(2)}
else {price[x] = setprices[x] * random(3)}
}
randomevent();
daysleft = daysleft-1;
AktieForm.left.value = daysleft;
AktieForm.spaceAvail.value = Number(sAvail -1);
AktieForm.spaceLeft.value = Number(sLeft);
if (daysleft == 1) alert("Detta är spelets sista dag!");
if (daysleft <= 0) {
alert("Du gjorde " + Currency(cash) + " kr på att handla med aktier!");
daysleft = 31;
for (x = 0; x < 20; x++){
yourAktier[x] = "";
yourprice[x] = ".";
quants[x] = "";
}
if (cash > oldScore) {
alert("GRATTIS!! du har slagit ditt gamla rekord!");
setCookie("www.jenic.nu - Aktie Kungen",cash,356);
oldScore = cash;
AktieForm.score.value = Currency(cash);
}
AktieForm.left.value = daysleft;
cash = 500;
AktieForm.money.value = Currency(cash);
sLeft = 0;
sAvail = 201;
AktieForm.spaceAvail.value = sAvail -1;
AktieForm.spaceLeft.value = sLeft;
showyours();
MaxMin();
return;
}
for (x = 0; x < 20; x++){
AktieForm.AktierForSale.options[x].text = Aktier[x];
AktieForm.AktiePrices.options[x].text = Currency(price[x]);
AktieForm.AktierForSale.selectedIndex = -1;
AktieForm.AktiePrices.selectedIndex = -1;
AktieForm.AktierYouHave.selectedIndex = -1;
AktieForm.AktierPrice.selectedIndex = -1;
AktieForm.money.value = Currency(cash);
AktieForm.AktieKursMax.selectedIndex = -1 ;
AktieForm.AktieKursMin.selectedIndex = -1 ;
}
}
StabilareKurs[x] = price[x];
RefreshSale();
showyours();
MaxMin();
StabilareKurser();
var sAvail = 201;
var sLeft = 0;
AktieForm.spaceAvail.value = sAvail -1;
AktieForm.spaceLeft.value = sLeft;
var oldScore = getCookie("www.jenic.nu - Aktie Kungen");
if (oldScore == null) oldScore = 0;
AktieForm.score.value = Currency(oldScore);
-->
</script>

Jesper TMedlem sedan nov. 20017 144 inlägg
#2
  1. I I.E. så går det inte att ta bort den fåniga ramen på något vättigt sätt, men du kan testa att göra en liten rövare med en div runt om och lite minus marginal:
<div style="background-color:white;width:20px;">
<select size="10" style="margin:-3px;">
  <option>Testar</option>
</select>
</div>
jenicpunktnuMedlem sedan juni 200343 inlägg
#3

TACK!
Har märkt att det ej verkar vara så smidigt, som man kanske tänkt sig.
Har försökt leta på de ställen jag har tillgång till, men dessvärre ej hittat något som verkar fungera...x(
Gör jag då alltså detta i...


<select name="AktierForSale" class="kursClass" size="20" ID="Select1"  onblur="return Select1_onblur()" style="margin:-3px;">

eller går jag in i var och varenda <select> och lägger in

<option style="margin:-3px;"></option>
<style type="text/css"> <!-- 

.kursClass { background-color:"white"; color:#999999; font-family:Verdana; font-size:10px; width:"*";  border:NONE;}

.impClass { font-family:Verdana; color:#999999; font-size:10px; border:NONE; }

</style>

<table ID="Table1" >
<tr >
<td >
<center>
 <font class="impClass" color="#000000">Aktie marknaden</font><br>
 <select name="AktierForSale" class="kursClass" size="20" ID="Select1"  onblur="return Select1_onblur()" >
<option runat></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
</select> <select name="AktiePrices" class="kursClass" size="20" ID="Select2" onblur="return Select2_onblur()" form action=".">
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
</select></center>
</td>
<td>
<center>
 <font class="impClass" color="#000000">Aktier du äger</font><br>
 <select name="AktierPrice" class="kursClass" size="20" ID="Select4">
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
</select>
<select name="AktierYouHave" class="kursClass" size="20" id="Select3" onblur="return Select1_onblur()">
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
</select> 
</center>
</td>

<td>
<center>
 <font class="impClass" color="#000000">max  /  min<br></font>
 <select name="AktieKursMax" class="kursClass" size="20" ID="Select5"  onblur="return Select1_onblur()" >
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
</select>
 <select name="AktieKursMin" class="kursClass" size="20" ID="Select6"  onblur="return Select1_onblur()" border="0">
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
</select> 
</center>
</td>

</tr>
</table>
Jesper TMedlem sedan nov. 20017 144 inlägg
#4

Om du använder en class så kan du ju lägga in margin:-3px; direkt i den (kursClass).

144 ms totalt · 3 externa anrop · v20260731065814-full.2b84b982
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
141 ms — hämta tråd, inlägg och bilagor (db)