根据选择重定向到新的网页


Redirect to new webpage based on choices

我想根据用户的选择引导用户进入不同的网站。我有麻烦找到在哪里做代码别的东西。就像现在一样,HTML占主导地位,它只指向它在action="…"中编写的内容。我希望我的解决方案是基于选择所做的选择,当按钮提交导航用户到正确的网站。

function byttMeny(){
    var username = "<?php echo $navn; ?>";
    var kundeMeny = document.getElementById("kunder");
    var prosjektMeny = document.getElementById("prosjekt");
    for(i = 0; i < kundeMeny.options.length; i++){
        var menu = kundeMeny.options[i].text;
        document.getElementById(menu).style.display = "none";
    }
    var currentMeny = kundeMeny.options[kundeMeny.selectedIndex].text; // Gir deg prosjektmeny utifra hva som er valgt i kundemeny
    document.getElementById(currentMeny).style.display = "block";
    document.getElementById("verdi").value = document.getElementById(currentMeny).options[document.getElementById(currentMeny).selectedIndex].text; 
    if(currentMeny == "Hydro")
    {
        var dropMeny = document.getElementById("Hydro");
        var valg = dropMeny.options[dropMeny.selectedIndex].text;
        document.getElementById("Kunde").value = "Hydro";
        if(valg == "Karmøy"){
            document.getElementById("kundevalg").action = "norsokgrupper.php";
        } else if(valg == "Noe annet"){ 
      document.getElementById("skjema").action = "noeannet.php";
        }
    } 
    else if(currentMeny == "Statoil")
    {
        var dropMeny = document.getElementById("Statoil");
        var valg = dropMeny.options[dropMeny.selectedIndex].text;
        document.getElementById("Kunde").value = "Statoil";
        if(valg == "Sverdrup"){
            document.getElementById("kundevalg").action = "norsokgrupper.php";
        } else if (valg == "noennet"){ 
            document.getElementById("skjema").action = "piss.php";
        }
    }
    else if(currentMeny == "Yara")
    {
        var dropMeny = document.getElementById("Yara");
        var valg = dropMeny.options[dropMeny.selectedIndex].text;
        document.getElementById("Kunde").value = "Yara";
        if(valg == "Sokli"){
            document.getElementById("kundevalg").action = "tull.php";
        } else if (valg == "noennet"){ 
       document.getElementById("skjema").action = "piss.php";
        }
    }
}

<form method="post" id="kundevalg"> 
    <div id="fixed-box" class="skygge">
<table>
        <h4 id="colorh4">Velg kunde og prosjekt</h4>

        <select id="kunder" name="kunder" onchange="byttMeny()">
            <?php
            {
            $sql = "select kundenavn from kunde";
            $resultat = mysqli_query($db, $sql);
            while($rad=mysqli_fetch_object($resultat))
            {
            $kunde = $rad->kundenavn;
            ?>
            <option> <?=$kunde?> </option>";
            <?php   
            }               
            ?>
        </select>
        <p></p>

            <select id="Hydro" type="text" name="Hydro" onchange="byttMeny()">   
                <?php 
                $sql = "select navn, prosjektid from prosjekt where kunde = 'Hydro'"; 
                $resultat = mysqli_query($db, $sql);
                mysqli_set_charset($db, "utf8");
                while ($rad = mysqli_fetch_object($resultat))
                  {
                $prosjekt = $rad->navn;
                ?>
                <option value="<?= $rad->prosjektid; ?>"> <?=$prosjekt?> </option>";       
                <?php 
                }
                ?>              
            </select>
            <select id="Statoil" type="text" name="Statoil"  onchange="byttMeny()">
                <?php 
                if($navn == "Martynas")
                {
                $sql = "select navn, prosjektid from prosjekt where kunde = 'Statoil'";
                $resultat = mysqli_query($db, $sql);
                while ($rad = mysqli_fetch_object($resultat))
                  {
                $prosjekt = $rad->navn;
                ?>
                <option value="<?= $rad->prosjektid; ?>"> <?=$prosjekt?> </option>
                <?php
                }
                ?>   
            </select>
             <select id="Yara" type="text" name="Yara"  onchange="byttMeny()">
                <?php 
                $sql = "select navn, prosjektid from prosjekt where kunde = 'Yara'";
                $resultat = mysqli_query($db, $sql);
                while ($rad = mysqli_fetch_object($resultat))
                  {
                $prosjekt = $rad->navn;
                ?>
                <option value="<?= $rad->prosjektid; ?>"> <?=$prosjekt?> </option>
                <?php
                }
                ?>   
            </select>

        <input id="neste_kunde" type="submit" name="neste" value="neste"/> 
        <input type="hidden" id="verdi" name="verdi" />
    </div>
</form>
      <div id="mcbilde">
          <img src="multibly2.jpg" class="stretch"/>
      <img src="mctr.png" class="trekant"/>
</div>

对于事件,您可以使用<a href="">Click me</a>

或者你可以将javascript事件绑定到按钮点击,像这样

<div onclick="myFunction()">Click me</div>

一个href click的例子Javascript onclick示例

应该可以:

<form method="post" id="kundevalg" onsubmit="redirect()"> 

JS:

function redirect(){
     document.getElementByTagId('kundevalg').action="http://newurl.com";
     return true;
}

应该可以了

// Bind a change event to the select input 
$('#Hydro').change( function(evt) { 
     // then use javascript to redirect to the value of the selected input
     window.location.href =  $(this).val();
});

可以使用键值创建映射。你可以在动态创建视图时决定视图