简体   繁体   English

根据选择重定向到新网页

[英]Redirect to new webpage based on choices

I want to direct the user in to different websites based on its choices. 我想根据用户的选择将用户定向到其他网站。 I have troubles to find where to do code something else. 我很难找到在其他地方编写代码的地方。 As now, the HTML is dominant and it diects only to what it is written in action="...". 像现在一样,HTML是主要的,它仅与action =“ ...”中编写的内容相同。 I want my solution to be based on the choices made in selects and when the button is submitted to navigate the user to correct website. 我希望我的解决方案基于选择中的选择以及提交按钮以导航用户以更正网站时的选择。

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>

For events you could use <a href="">Click me</a> 对于事件,您可以使用<a href="">Click me</a>

Or you can bind javascript events to button click like so 或者您可以像这样将javascript事件绑定到按钮单击

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

A href click example Javascript onclick example href点击示例 Javascript onclick示例

This should work: 这应该工作:

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

JS: JS:

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

This should do the trick 这应该可以解决问题

// 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();

});

You can create a map with key value. 您可以使用键值创建地图。 and depending upon the you can decide the view while creating the view dynamically. 并且可以根据需要在动态创建视图时决定视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM