Gå til innhold

Hvordan skrives dette i Action Script?


Anbefalte innlegg

Videoannonse
Annonse

Noe som dette?

 

var firstNumber = parseInt(document.getElementById('input-field-1'), 10);
var secondNumber = parseInt(document.getElementById('input-field-2'), 10);
if (!isNaN(firstNumbeR) && !isNaN(secondNumber) && firstNumber > secondNumber) {
document.getElementById('form-label-1').innerHTML = document.getElementById('input-text-1').value;
document.getElementById('form-label-2').innerHTML = firstNumber * 1000;
}

Lenke til kommentar

Ser jeg glemte litt av koden i førstepost. Glemte "else".

 

if(Convert.ToInt32(TextBox1.Text) > Convert.ToInt32(TextBox11.Text))
       {
           Label1.Text = TextBox1.Text;
           Label11.Text = Convert.ToString((Convert.ToInt32(TextBox1.Text))*1000);
       }
       else
       {
           Label1.Text = Convert.ToString((Convert.ToInt32(TextBox11.Text)) / 1000);
           Label11.Text = TextBox11.Text;
       }

 

Er ganske rett fram. Skal kopiere over det tallet som er høyest i enten input 1 eller input 2, over til en label/tekstbox. Skal ha 10 koloner med samme. Og så skal det legges sammen i en ny label. Rett og slett så enkelt.

Lenke til kommentar

C#

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title>Kassaopptelling</title>
   <style type="text/css">
       .style1
       {
           width: 1000px;
       }
       .style2
       {
           font-weight: bold;
       }
   </style>
</head>
<body style="font-family: 'Myriad Pro'">
   <form id="form1" runat="server">
   <div>

       <h1>
           Kassaopptelling</h1>
       <p>
           Hvor mye skal det være i kassa (136 -> kassastatus): 
           <asp:TextBox ID="TextBox21" runat="server"></asp:TextBox>
       </p>
       <table cellpadding="0" cellspacing="0" class="style1">
           <tr>
               <td class="style2">
                   Antall::</td>
               <td>
                   <b>Antall:</b></td>
               <td>
                   <b>KR:</b></td>
               <td>
                   <b>Utregning (antall):</b></td>
               <td>
                   <b>Utregning (KR):</b></td>
           </tr>
           <tr>
               <td>
                   <b>1000- lapper</b></td>
               <td>
                   <asp:TextBox ID="TextBox1" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:TextBox ID="TextBox11" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
               </td>
               <td>
                   <asp:Label ID="Label11" runat="server" Text=""></asp:Label>
               </td>
           </tr>
           <tr>
               <td>
                   <b>500- lapper</b></td>
               <td>
                   <asp:TextBox ID="TextBox2" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:TextBox ID="TextBox12" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
               </td>
               <td>
                   <asp:Label ID="Label12" runat="server" Text=""></asp:Label>
               </td>
           </tr>
           <tr>
               <td>
                   <b>200- lapper</b></td>
               <td>
                   <asp:TextBox ID="TextBox3" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:TextBox ID="TextBox13" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:Label ID="Label3" runat="server" Text=""></asp:Label>
               </td>
               <td>
                   <asp:Label ID="Label13" runat="server" Text=""></asp:Label>
               </td>
           </tr>
           <tr>
               <td>
                   <b>100- lapper</b></td>
               <td>
                   <asp:TextBox ID="TextBox4" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:TextBox ID="TextBox14" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:Label ID="Label4" runat="server" Text=""></asp:Label>
               </td>
               <td>
                   <asp:Label ID="Label14" runat="server" Text=""></asp:Label>
               </td>
           </tr>
           <tr>
               <td>
                   <b>50- lapper</b></td>
               <td>
                   <asp:TextBox ID="TextBox5" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:TextBox ID="TextBox15" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:Label ID="Label5" runat="server" Text=""></asp:Label>
               </td>
               <td>
                   <asp:Label ID="Label15" runat="server" Text=""></asp:Label>
               </td>
           </tr>
           <tr>
               <td>
                   <b>20- kroner</b></td>
               <td>
                   <asp:TextBox ID="TextBox6" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:TextBox ID="TextBox16" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:Label ID="Label6" runat="server" Text=""></asp:Label>
               </td>
               <td>
                   <asp:Label ID="Label16" runat="server" Text=""></asp:Label>
               </td>
           </tr>
           <tr>
               <td>
                   <b>10- kroner</b></td>
               <td>
                   <asp:TextBox ID="TextBox7" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:TextBox ID="TextBox17" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:Label ID="Label7" runat="server" Text=""></asp:Label>
               </td>
               <td>
                   <asp:Label ID="Label17" runat="server" Text=""></asp:Label>
               </td>
           </tr>
           <tr>
               <td>
                   <b>5- kroner</b></td>
               <td>
                   <asp:TextBox ID="TextBox8" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:TextBox ID="TextBox18" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:Label ID="Label8" runat="server" Text=""></asp:Label>
               </td>
               <td>
                   <asp:Label ID="Label18" runat="server" Text=""></asp:Label>
               </td>
           </tr>
           <tr>
               <td>
                   <b>1- kroner</b></td>
               <td>
                   <asp:TextBox ID="TextBox9" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:TextBox ID="TextBox19" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:Label ID="Label9" runat="server" Text=""></asp:Label>
               </td>
               <td>
                   <asp:Label ID="Label19" runat="server" Text=""></asp:Label>
               </td>
           </tr>
           <tr>
               <td>
                   <b>50- ører</b></td>
               <td>
                   <asp:TextBox ID="TextBox10" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:TextBox ID="TextBox20" runat="server">0</asp:TextBox>
               </td>
               <td>
                   <asp:Label ID="Label10" runat="server" Text=""></asp:Label>
               </td>
               <td>
                   <asp:Label ID="Label20" runat="server" Text=""></asp:Label>
               </td>
           </tr>
           <tr>
               <td colspan="4">
                  Sum</td>
               <td>
                   <asp:Label ID="Label21" runat="server"></asp:Label>
               </td>
           </tr>
       </table>

   </div>
   <p>
       <asp:Button ID="Button1" runat="server" Text="Oppdater" 
           onclick="Button1_Click" />
 <asp:Button ID="Button2" runat="server" Text="Slett alle" 
           onclick="Button2_Click" />
   </p>
   </form>
</body>
</html>

 

 

CS- fila

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {

   }
   protected void Button1_Click(object sender, EventArgs e)
   {
       int sum;
       double sumore, diff, veksel;

       //1000- lapper
       if(Convert.ToInt32(TextBox1.Text) > Convert.ToInt32(TextBox11.Text))
       {
           Label1.Text = TextBox1.Text;
           Label11.Text = Convert.ToString((Convert.ToInt32(TextBox1.Text))*1000);
       }
       else
       {
           Label1.Text = Convert.ToString((Convert.ToInt32(TextBox11.Text)) / 1000);
           Label11.Text = TextBox11.Text;
       }

       //500- lapper
       if (Convert.ToInt32(TextBox2.Text) > Convert.ToInt32(TextBox12.Text))
       {
           Label2.Text = TextBox2.Text;
           Label12.Text = Convert.ToString((Convert.ToInt32(TextBox2.Text)) * 500);
       }
       else
       {
           Label2.Text = Convert.ToString((Convert.ToInt32(TextBox12.Text)) / 500);
           Label12.Text = TextBox12.Text;
       }

       //200- lapper
       if (Convert.ToInt32(TextBox3.Text) > Convert.ToInt32(TextBox13.Text))
       {
           Label3.Text = TextBox3.Text;
           Label13.Text = Convert.ToString((Convert.ToInt32(TextBox3.Text)) * 200);
       }
       else
       {
           Label3.Text = Convert.ToString((Convert.ToInt32(TextBox13.Text)) / 200);
           Label13.Text = TextBox13.Text;
       }

       //100- lapper
       if (Convert.ToInt32(TextBox4.Text) > Convert.ToInt32(TextBox14.Text))
       {
           Label4.Text = TextBox4.Text;
           Label14.Text = Convert.ToString((Convert.ToInt32(TextBox4.Text)) * 100);
       }
       else
       {
           Label4.Text = Convert.ToString((Convert.ToInt32(TextBox14.Text)) / 100);
           Label14.Text = TextBox14.Text;
       }

       //50- lapper
       if (Convert.ToInt32(TextBox5.Text) > Convert.ToInt32(TextBox15.Text))
       {
           Label5.Text = TextBox5.Text;
           Label15.Text = Convert.ToString((Convert.ToInt32(TextBox5.Text)) * 50);
       }
       else
       {
           Label5.Text = Convert.ToString((Convert.ToInt32(TextBox15.Text)) / 50);
           Label15.Text = TextBox15.Text;
       }

       //20- kroner
       if (Convert.ToInt32(TextBox6.Text) > Convert.ToInt32(TextBox16.Text))
       {
           Label6.Text = TextBox6.Text;
           Label16.Text = Convert.ToString((Convert.ToInt32(TextBox6.Text)) * 20);
       }
       else
       {
           Label6.Text = Convert.ToString((Convert.ToInt32(TextBox16.Text)) / 20);
           Label16.Text = TextBox16.Text;
       }

       //10- kroner
       if (Convert.ToInt32(TextBox7.Text) > Convert.ToInt32(TextBox17.Text))
       {
           Label7.Text = TextBox1.Text;
           Label17.Text = Convert.ToString((Convert.ToInt32(TextBox7.Text)) * 10);
       }
       else
       {
           Label7.Text = Convert.ToString((Convert.ToInt32(TextBox17.Text)) / 10);
           Label17.Text = TextBox17.Text;
       }

       //5- kroner
       if (Convert.ToInt32(TextBox8.Text) > Convert.ToInt32(TextBox18.Text))
       {
           Label8.Text = TextBox8.Text;
           Label18.Text = Convert.ToString((Convert.ToInt32(TextBox8.Text)) * 5);
       }
       else
       {
           Label8.Text = Convert.ToString((Convert.ToInt32(TextBox18.Text)) / 5);
           Label18.Text = TextBox18.Text;
       }

       //1- kroner
       if (Convert.ToInt32(TextBox9.Text) > Convert.ToInt32(TextBox19.Text))
       {
           Label9.Text = TextBox9.Text;
           Label19.Text = Convert.ToString((Convert.ToInt32(TextBox9.Text)));
       }
       else
       {
           Label9.Text = Convert.ToString((Convert.ToInt32(TextBox19.Text)));
           Label19.Text = TextBox19.Text;
       }

       //50- ører
       if (Convert.ToInt32(TextBox10.Text) > Convert.ToInt32(TextBox20.Text))
       {
           Label10.Text = TextBox10.Text;
           Label20.Text = Convert.ToString((Convert.ToInt32(TextBox10.Text)) * 0.5);
       }
       else
       {
           Label10.Text = Convert.ToString((Convert.ToInt32(TextBox20.Text)) / 0.5);
           Label20.Text = TextBox20.Text;
       }

       sum = Convert.ToInt32(Label11.Text) + Convert.ToInt32(Label12.Text) + Convert.ToInt32(Label13.Text) + Convert.ToInt32(Label14.Text) + Convert.ToInt32(Label15.Text) + Convert.ToInt32(Label16.Text) + Convert.ToInt32(Label17.Text) + Convert.ToInt32(Label18.Text) + Convert.ToInt32(Label19.Text);
       sumore = Convert.ToDouble(sum) + Convert.ToDouble(Label20.Text);

       if (Convert.ToDouble(Label20.Text) > 0.4)
       {
           Label21.Text = Convert.ToString(sumore);
       }
       else
       {
           Label21.Text = Convert.ToString(sum);
       }

   }
   protected void Button2_Click(object sender, EventArgs e)
   {
       TextBox1.Text = "0";
       TextBox2.Text = "0";
       TextBox3.Text = "0";
       TextBox4.Text = "0";
       TextBox5.Text = "0";
       TextBox6.Text = "0";
       TextBox7.Text = "0";
       TextBox8.Text = "0";
       TextBox9.Text = "0";
       TextBox10.Text = "0";
       TextBox11.Text = "0";
       TextBox12.Text = "0";
       TextBox13.Text = "0";
       TextBox14.Text = "0";
       TextBox15.Text = "0";
       TextBox16.Text = "0";
       TextBox17.Text = "0";
       TextBox18.Text = "0";
       TextBox19.Text = "0";
       TextBox20.Text = "0";

       Label1.Text = "0";
       Label2.Text = "0";
       Label3.Text = "0";
       Label4.Text = "0";
       Label5.Text = "0";
       Label6.Text = "0";
       Label7.Text = "0";
       Label8.Text = "0";
       Label9.Text = "0";
       Label10.Text = "0";
       Label11.Text = "0";
       Label12.Text = "0";
       Label13.Text = "0";
       Label14.Text = "0";
       Label15.Text = "0";
       Label16.Text = "0";
       Label17.Text = "0";
       Label18.Text = "0";
       Label19.Text = "0";
       Label20.Text = "0";
       Label21.Text = "0";
   }
}

 

Endret av Gregory House
Lenke til kommentar

:green:

 



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
Kassaopptelling
</title>
   <style type="text/css">
       .style1
       {
           width: 1000px;
       }
       .style2
       {
           font-weight: bold;
       }
   </style>
</head>
<body style="font-family: 'Myriad Pro'">
   <form method="post" action="Default.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE1MDYwMDM4ODdkZGnbZxlGYJTU9hAzzkjzms6UNnYuksOvkqM+mbDUgNRY" />
</div>

<div class="aspNetHidden">

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWGALxkqbxCAKq1LDQCQLs0bLrBgKq1OzhAwLs0fbZDAKr1OzhAwLs0Yq1BQKs1OzhAwLs0e58Aq3U7OEDAuzRgtgJAq7U7OEDAuzRxsYPAq/U7OEDAuzR2qEIArDU7OEDAuzR/rYIAqHU7OEDAuzRkpIBAqLU7OEDAqnU7OEDAqnUsNAJAoznisYGArursYYIgbKYVOJM/aGCFbo/hn8IVBNkaiCFqDpHFdjRAgDJo1o=" />
</div>
   <div>

       <h1>
           Kassaopptelling</h1>
       <p>
           Hvor mye skal det være i kassa (136 -> kassastatus): 
           <input name="TextBox21" type="text" id="TextBox21" />
       </p>
       <table cellpadding="0" cellspacing="0" class="style1">
           <tr>
               <td class="style2">
                   Antall::</td>
               <td>
                   <b>Antall:</b></td>
               <td>
                   <b>KR:</b></td>
               <td>
                   <b>Utregning (antall):</b></td>
               <td>
                   <b>Utregning (KR):</b></td>
           </tr>
           <tr>
               <td>
                   <b>1000- lapper</b></td>
               <td>
                   <input name="TextBox1" type="text" value="0" id="TextBox1" />
               </td>
               <td>
                   <input name="TextBox11" type="text" value="0" id="TextBox11" />
               </td>
               <td>
                   <span id="Label1"></span>
               </td>
               <td>
                   <span id="Label11"></span>
               </td>
           </tr>
           <tr>
               <td>
                   <b>500- lapper</b></td>
               <td>
                   <input name="TextBox2" type="text" value="0" id="TextBox2" />
               </td>
               <td>
                   <input name="TextBox12" type="text" value="0" id="TextBox12" />
               </td>
               <td>
                   <span id="Label2"></span>
               </td>
               <td>
                   <span id="Label12"></span>
               </td>
           </tr>
           <tr>
               <td>
                   <b>200- lapper</b></td>
               <td>
                   <input name="TextBox3" type="text" value="0" id="TextBox3" />
               </td>
               <td>
                   <input name="TextBox13" type="text" value="0" id="TextBox13" />
               </td>
               <td>
                   <span id="Label3"></span>
               </td>
               <td>
                   <span id="Label13"></span>
               </td>
           </tr>
           <tr>
               <td>
                   <b>100- lapper</b></td>
               <td>
                   <input name="TextBox4" type="text" value="0" id="TextBox4" />
               </td>
               <td>
                   <input name="TextBox14" type="text" value="0" id="TextBox14" />
               </td>
               <td>
                   <span id="Label4"></span>
               </td>
               <td>
                   <span id="Label14"></span>
               </td>
           </tr>
           <tr>
               <td>
                   <b>50- lapper</b></td>
               <td>
                   <input name="TextBox5" type="text" value="0" id="TextBox5" />
               </td>
               <td>
                   <input name="TextBox15" type="text" value="0" id="TextBox15" />
               </td>
               <td>
                   <span id="Label5"></span>
               </td>
               <td>
                   <span id="Label15"></span>
               </td>
           </tr>
           <tr>
               <td>
                   <b>20- kroner</b></td>
               <td>
                   <input name="TextBox6" type="text" value="0" id="TextBox6" />
               </td>
               <td>
                   <input name="TextBox16" type="text" value="0" id="TextBox16" />
               </td>
               <td>
                   <span id="Label6"></span>
               </td>
               <td>
                   <span id="Label16"></span>
               </td>
           </tr>
           <tr>
               <td>
                   <b>10- kroner</b></td>
               <td>
                   <input name="TextBox7" type="text" value="0" id="TextBox7" />
               </td>
               <td>
                   <input name="TextBox17" type="text" value="0" id="TextBox17" />
               </td>
               <td>
                   <span id="Label7"></span>
               </td>
               <td>
                   <span id="Label17"></span>
               </td>
           </tr>
           <tr>
               <td>
                   <b>5- kroner</b></td>
               <td>
                   <input name="TextBox8" type="text" value="0" id="TextBox8" />
               </td>
               <td>
                   <input name="TextBox18" type="text" value="0" id="TextBox18" />
               </td>
               <td>
                   <span id="Label8"></span>
               </td>
               <td>
                   <span id="Label18"></span>
               </td>
           </tr>
           <tr>
               <td>
                   <b>1- kroner</b></td>
               <td>
                   <input name="TextBox9" type="text" value="0" id="TextBox9" />
               </td>
               <td>
                   <input name="TextBox19" type="text" value="0" id="TextBox19" />
               </td>
               <td>
                   <span id="Label9"></span>
               </td>
               <td>
                   <span id="Label19"></span>
               </td>
           </tr>
           <tr>
               <td>
                   <b>50- ører</b></td>
               <td>
                   <input name="TextBox10" type="text" value="0" id="TextBox10" />
               </td>
               <td>
                   <input name="TextBox20" type="text" value="0" id="TextBox20" />
               </td>
               <td>
                   <span id="Label10"></span>
               </td>
               <td>
                   <span id="Label20"></span>
               </td>
           </tr>
           <tr>
               <td colspan="4">
                  Sum</td>
               <td>
                   <span id="Label21"></span>
               </td>
           </tr>
       </table>

   </div>
   <p>
       <input type="submit" name="Button1" value="Oppdater" id="Button1" />
 <input type="submit" name="Button2" value="Slett alle" id="Button2" />
   </p>
   </form>
</body>
</html>

Lenke til kommentar

var firstNumber = parseInt(document.getElementById('TextBox1'), 10);
var secondNumber = parseInt(document.getElementById('TextBox11'), 10);
if (isNaN(firstNumber) || isNaN(secondNumber)) {
//return or continue;
}
if (firstNumber > secondNumber) {
document.getElementById('Label1').innerHTML = firstNumber;
document.getElementById('Label11').innerHTML = firstNumber * 1000;
} else {
document.getElementById('Label1').innerHTML = secondNumber / 1000;
document.getElementById('Label11').innerHTML = secondNumber;
}

Kan ikke si jeg er fan av HTML-en din.

Lenke til kommentar

En liten forskjell ja... :wee:

 

Skriver nå i 2.0 og programmet er nesten ferdig. Mangler bare denne lille mattebiten.

 

int num1 = parseInt(Text1.text);
int num2 = parseInt(Text2.text);

if(num1 > num2) {
Label1.text = Text1.text;
Label2.text = num1 * 1000;
} else {
Label1.text = num2 / 1000;
Label2.text = Text1.text;
}

 

Hva er feil?

Endret av Gregory House
Lenke til kommentar

Ingenting...

 

num1 = parseInt(Text1.text);
num2 = parseInt(Text2.text);

if(num1 > (num2/1000)) {
Label1.text = Text1.text;
Label2.text = num1 * 1000;
} else {
Label1.text = num2 / 1000;
Label2.text = Text2.text;
}

 

Dette funker. Men... Hvordan skal jeg få den til å virke uten å bruke knapp? Den funker fint om jeg legger koden på en knapp og legger til on (release), men ikke om jeg legger koden i keyframe.

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...