Avatar billede leif7 Nybegynder
30. oktober 2000 - 16:58 Der er 5 kommentarer og
1 løsning

DIV, radiobutton og javascript

Her er lidt kode jeg har lånt fra et andet sted:)
Mit problem er at jeg har brug for at indsætte \"radiobuttons\" i stedet for \"text\" og \"select\". Hvordan kan jeg indsætte radiobuttons og tjekke på værdien i et javascript???

<html>
<head>
<title>Seismic Loading Calculator</title>
</head>
<body BGCOLOR=\"Silver\">
<!-- Persistant Elements Begin -->
<img SRC=\"quake.gif\" STYLE=\"position:absolute; top:1; left:1;\" WIDTH=\"75\" HEIGHT=\"200\">
<hr STYLE=\"position:absolute; top:210; left:0;\">
<button DISABLED STYLE=\"position:absolute; top:220; left:295;\" ID=\"Back\" ACCESSKEY=\"N\" TITLE=\"Next\" onClick=\"goBack();\">
&lt; Back
</button>
<button STYLE=\"position:absolute; top:220; left:365;\" ID=\"Next\" ACCESSKEY=\"N\" TITLE=\"Next\" onClick=\"goNext();\">
Next &gt;
</button>
<button STYLE=\"position:absolute; top:220; left:428;\" ID=\"Finish\" ACCESSKEY=\"N\" TITLE=\"Cancel\" onClick=\"closedialog();\">
Cancel
</button>
<!-- Persistant Elements End -->
<div ID=\"Pane1\" STYLE=\"position:absolute; top:1; left:80; height:200; width:400; visibility: hidden;\">
<h4>Welcome to the Seismic Load Calculator</h4>
<p>This simple wizard will assist you in determining the maximum design base shear for the building you specify. This wizard\'s calculations are based on the 1994 Uniform Building Code.</p>
<p>Click Next to begin</p>
</div>
<div ID=\"Pane2\" STYLE=\"position:absolute; top:1; left:80; height:200; width:400; visibility: hidden;\">
<h4>Building Height</h4>
<p>What is the floor-to-floor height of the building in feet?&nbsp;&nbsp;<input TYPE=\"TEXT\" ID=\"dlgheight\" SIZE=\"3\" VALUE=\"15\"> feet</p>
<p>How many floors are in the building?&nbsp;&nbsp;<input TYPE=\"TEXT\" ID=\"dlgfloors\" SIZE=\"3\" VALUE=\"10\"> floors</p>
</div>
<div ID=\"Pane3\" STYLE=\"position:absolute; top:1; left:80; height:200; width:400; visibility: hidden;\">
<h4>Building Mass</h4>
<fieldset>
<legend>Building Dimensions</legend>
What is length of the building? &nbsp;&nbsp;<input TYPE=\"TEXT\" ID=\"dlglength\" SIZE=\"3\" VALUE=\"100\"> feet<br>
What is width of the building?&nbsp;&nbsp;<input TYPE=\"TEXT\" ID=\"dlgwidth\" SIZE=\"3\" VALUE=\"100\"> feet
</fieldset>
<fieldset>
<legend>Building Loading</legend>
What is the dead-load in psf for the building?&nbsp;&nbsp;<input TYPE=\"TEXT\" ID=\"dlgdead\" SIZE=\"3\" VALUE=\"20\"> psf<br>
What is the live-load in psf for the building?&nbsp;&nbsp;<input TYPE=\"TEXT\" ID=\"dlglive\" SIZE=\"3\" VALUE=\"50\"> psf
</fieldset>
</div>
<div ID=\"Pane4\" STYLE=\"position:absolute; top:1; left:80; height:200; width:400; visibility: hidden;\">
<h4>Building Importance</h4>
<p>The importance factor will add additional seismic load requirements to your building if your building is deamed an essential structure in a natural disaster.</p>
<fieldset>
    <legend>Importance Factor</legend>
    <select ID=\"dlgImport\">
        <option CHECKED VALUE=\"1\">This is a standard building
        <option VALUE=\"1.5\">This is an important, essential building
    </select></fieldset>

</div>
<div ID=\"Pane5\" STYLE=\"position:absolute; top:1; left:80; height:200; width:400; visibility: hidden;\">
<h4>Building Structure</h4>
<p>Please specify the intended strcutural system. The intended structural system will take into account both the material selected and the ductility of the structural system selected.</p>
<fieldset>
    <legend>Structural System</legend>
    <select ID=\"dlgStructure\">
        <option CHECKED VALUE=\"SMRF\">Steel Moment Resisting Frame
        <option VALUE=\"CMRF\">Concrete Moment Resisting Frame
        <option VALUE=\"SHER\">Rigid Shear Wall
        <option VALUE=\"WOOD\">Plywood Shear Wall
    </select>
</fieldset>
</div>
<div ID=\"Pane6\" STYLE=\"position:absolute; top:1; left:80; height:200; width:400; visibility: hidden;\">
<h4>Building Site</h4>
<p>Please specify the following information as indicated by your soils engineer or soils report.
<fieldset>
<legend>UBC Seismic Zone</legend>
    <select ID=\"dlgZone\">
        <option CHECKED VALUE=\"0.4\">Zone 4 (High Seismicity)
        <option VALUE=\"0.3\">Zone 3
        <option VALUE=\"0.2\">Zone 2
        <option VALUE=\"0.1\">Zone 1 (Low Seismicity)
    </select>
</fieldset>
<br>
<fieldset>
<legend>UBC Soil Factor</legend>
    <select ID=\"dlgSoil\">
        <option VALUE=\"1\">1.5 - Hard Soil
        <option VALUE=\"1.2\">1.2 - Moderate Soil
        <option CHECKED VALUE=\"1.5\">1.5 - Normal Soil
        <option VALUE=\"2.0\">2.0 -  Soft Soil
    </select>
</fieldset>
</div>
<div ID=\"Pane7\" STYLE=\"position:absolute; top:1; left:80; height:200; width:400; visibility: hidden;\">
<h4>Send Data to the Server</h4>
<p>We have now collected all of the necissary information and we are ready to send that information to our server for processing.</p>
<p>Click \'Send\' when you are ready to send the information to the server</p>
</div>
<script LANGUAGE=\"JavaScript\" FOR=\"window\" EVENT=\"onLoad\">
document.all.Pane1.style.visibility = \"\";
</script>
<script LANGUAGE=\"JavaScript\">
var currentpane = 1;
function check2()
    {
    if ((isNaN(dlgheight.value) == true) || (dlgheight.value == \"\"))
    {
        alert(\"You must specify a real number for the floor-to-floor height of the building\");
        return false;
    }
    if ((dlgheight.value > 15) || (dlgheight.value < 10))
    {
        alert(\"Please use a floor-to-floor height between 10 and 15 feet\");
        return false;
    }
    if ((isNaN(dlgfloors.value) == true) || (dlgfloors.value == \"\"))
    {
        alert(\"You must specify a real number for the number of floors\");
        return false;
    }
    if ((dlgfloors.value > 30) || (dlgfloors.value < 1))
    {
        alert(\"Our calculator is only approved for buildings under 30 stories\");
        return false;
    }
    return true;
    }
function check3()
    {
    if ((isNaN(dlglength.value) == true) || (dlglength.value == \"\"))
    {
        alert(\"You must specify a real number for the length of the building\");
        return false;
    }
    if ((dlglength.value > 200) || (dlglength.value < 1))
    {
        alert(\"Our calculator is only approved for buildings less than 200 feet long\");
        return false;
    }
    if ((isNaN(dlgwidth.value) == true) || (dlgwidth.value == \"\"))
    {
        alert(\"You must specify a real number for the width of the building\");
        return false;
    }
    if ((dlgwidth.value > 200) || (dlgwidth.value < 1))
    {
        alert(\"Our calculator is only approved for buildings less than 200 feet long\");
        return false;
    }
    if ((isNaN(dlgdead.value) == true) || (dlgdead.value == \"\"))
    {
        alert(\"You must specify a real number for the dead-load of the building\");
        return false;
    }
    if ((dlgdead.value > 50) || (dlgdead.value < 1))
    {
        alert(\"Our calculator is only approved for buildings with a dead load less than 50 psf\");
        return false;
    }
    if ((isNaN(dlglive.value) == true) || (dlglive.value == \"\"))
    {
        alert(\"You must specify a real number for the live-load of the building\");
        return false;
    }
    if ((dlglive.value > 75) || (dlglive.value < 1))
    {
        alert(\"Our calculator is only approved for buildings with a dead load less than 75 psf\");
        return false;
    }
    return true;
    }
function goBack()
    {
    if (currentpane == 2)
    {
        document.all.Pane1.style.visibility = \"\";
        document.all.Pane2.style.visibility = \"hidden\";
        Back.disabled = 1;
    }
    if (currentpane == 3)
    {
        document.all.Pane2.style.visibility = \"\";
        document.all.Pane3.style.visibility = \"hidden\";
    }
    if (currentpane == 4)
    {
        document.all.Pane3.style.visibility = \"\";
        document.all.Pane4.style.visibility = \"hidden\";
    }
    if (currentpane == 5)
    {
        document.all.Pane4.style.visibility = \"\";
        document.all.Pane5.style.visibility = \"hidden\";
    }
    if (currentpane == 6)
    {
        document.all.Pane5.style.visibility = \"\";
        document.all.Pane6.style.visibility = \"hidden\";
    }
    if (currentpane == 7)
    {
        document.all.Pane6.style.visibility = \"\";
        document.all.Pane7.style.visibility = \"hidden\";
        Next.disabled = 0;
        Finish.innerHTML = \"Cancel\";
    }
    currentpane -= 1
    }
function goNext()
    {
    if (currentpane == 1)
    {
        document.all.Pane1.style.visibility = \"hidden\";
        document.all.Pane2.style.visibility = \"\";
        Back.disabled = 0;
    }
    if (currentpane == 2)
    {
        if (check2() == true)
        {
        document.all.Pane2.style.visibility = \"hidden\";
        document.all.Pane3.style.visibility = \"\";
        }
        else
        {
        return false;
        }
    }
    if (currentpane == 3)
    {
        if (check3() == true)
        {
        document.all.Pane3.style.visibility = \"hidden\";
        document.all.Pane4.style.visibility = \"\";
        }
        else
        {
        return false;
        }
    }
    if (currentpane == 4)
    {
        document.all.Pane4.style.visibility = \"hidden\";
        document.all.Pane5.style.visibility = \"\";
    }
    if (currentpane == 5)
    {
        document.all.Pane5.style.visibility = \"hidden\";
        document.all.Pane6.style.visibility = \"\";
    }
    if (currentpane == 6)
    {
        document.all.Pane6.style.visibility = \"hidden\";
        document.all.Pane7.style.visibility = \"\";
        Next.disabled = 1;
        Finish.innerHTML = \"Send\";
    }
    currentpane += 1
    }

function closedialog()
    {
    if (currentpane == 7)
        {
        strpath=\"seismic.asp?Stuff=Yes&Height=\" + dlgheight.value + \"&Floors=\" + dlgfloors.value + \"&Length=\" + dlglength.value + \"&Width=\" + dlgwidth.value + \"&Dead=\" + dlgdead.value + \"&Live=\" + dlglive.value + \"&Import=\" + dlgImport.value + \"&Stucture=\" + dlgStructure.value + \"&Zone=\" + dlgZone.value + \"&Soil=\" + dlgSoil.value
        window.returnValue = strpath;
        window.close();
        }
    else
        {
            if (confirm(\"Are you sure that you want to quit?\"))
            {
                window.close();
            }
        }
    }
</script>
</body>
</html>
Avatar billede ldanielsen Nybegynder
30. oktober 2000 - 22:25 #1
Checke radiobuttons, OK:

function radioChecker(){
  var checkedRadio= \"\"
  for (var i in document.musicForm.musicType){
    if (document.myForm.myRadio[i].checked==\"1\"){
      checkedRadio=document.myForm.myRadio[i].value
      } 
    }
  return checkedRadio
  }

Den returnerer value for den der er klikket på, eller \"\" hvis der ingen er valgt.
Avatar billede leif7 Nybegynder
31. oktober 2000 - 11:55 #2
<div ID=\"Pane2\" STYLE=\"position:absolute; top:1; left:80; height:220; width:475; visibility: hidden;\">
<form name=\"f0\">
<h4><%= S0 %></h4>
&nbsp;&nbsp;<INPUT type=\"radio\" name=\"phone\" value=\"1\" >&nbsp;&nbsp;<%=S0Q1%><BR>
&nbsp;&nbsp;<INPUT type=\"radio\" name=\"phone\" value=\"2\" >&nbsp;&nbsp;<%=S0Q2%>
</form>
</div>
...klip
function S0Value()
    {
    var pos = \"\"
    for (var i in document.f0.phone){
      if (document.f0.phone[i].checked == \"1\"){
          pos = document.f0.phone[i].value ;
          alert(\"aaa\");
          }
      }
    alert(pos);
    return pos;
    }
function checkS0()
    {
      var value = S0Value()
      if (i == \"\")
      {
          alert(\"fejl 2\");
          return false;
      }

den når aldrig ind i \"if (document.f0.phone[i].checked == \"1\")\" løkken? Hvad går går galt?
Avatar billede leif7 Nybegynder
31. oktober 2000 - 12:02 #3
function checkS0()
    {
      var value = S0Value()
      if (value == \"\")
      {
          alert(\"fejl 2\");
          return false;
      }

Avatar billede ldanielsen Nybegynder
31. oktober 2000 - 13:22 #4
Prøv denne løkke i stedet, den virker for mig i msie:

for (i=0;i<document.f0.phone.length;i++) {
  if (document.f0.phone[i].checked){
    pos = document.f0.phone[i].value
    }
  }
Avatar billede ldanielsen Nybegynder
31. oktober 2000 - 13:23 #5
Sikkert fordi den ikke forstår \"1\" som true.

De gør netscape.
Avatar billede leif7 Nybegynder
31. oktober 2000 - 14:10 #6
Jubii...!!! Det virker sørme også for mig. Jeg er dig evigt taknemlig! Tusind tak.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester