0

I have this code that when users select a specific value it will go to that URL. But i only have the HTML part.

For example:

Urgency = High || Impact = Site/Dept || Platform = Unix & Windows

When they click submit they will go to a URL base on those choices

It is like High + Site/Dept + Unix & Windows = URL1.... and so on.

I only have the HTML codes i found during my research but i'm not that good in javascript so i can't seems to find the logic on how to make this work.

Also I'm using sharepoint webpart Content Editor

I can't add the code here so i just put it on the link below

Link for the code

Sample conditions:

I hope the below conditions answers your question. But it is a lot so i gave a few examples

Urgency & Impact = Show All; Platform = All Checked => Homepage

Urgency = High & Impact = Show All; Platform = All Checked => URL1

Urgency = Low & Impact = Show All; Platform = All Checked => URL2

Urgency = Show All & Impact = Site/Dept; Platform = All Checked => URL3

Urgency = Show All & Impact = Multiple Users; Platform = All Checked => URL4

Urgency & Impact = Show All; Platform = Unix&Windows => URL5

2
  • Can you please specify all the conditions for the urls? Commented Dec 8, 2019 at 10:36
  • Hi Harshal i added the conditions. I hope it answered your question
    – JunTan
    Commented Dec 8, 2019 at 10:55

2 Answers 2

2

The following example code for your reference.

<div>Urgency</div>
<select id="urgencyMenu">
  <option selected="selected" value="Show All">Show All</option>
  <option value="High">High</option>
  <option value="Low">Low</option>
</select>
<div>Impact</div>
<select id="impactMenu">
    <option selected="selected" value="Show All">Show All</option>
    <option value="Site/Dept">Site/Dept</option>
    <option value="Multiple Users">Multiple Users</option>
</select>
<br/>
<div>Platform</div> 
<input id="platform" checked type="checkbox" name="platform" value="Unix">Unix
<input id="platform" checked type="checkbox" name="platform" value="Windows">Windows
<input id="platform" checked type="checkbox" name="platform" value="Network">Network<br><br>
<br/>
<input type="button" onclick="SubmitClicked()" id="go" value="Submit">
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
function SubmitClicked(){
    var urgency = $("#urgencyMenu").val();
    var impact = $("#impactMenu").val();
    var platform = $("input[name='platform']:checked").map(function() {
        return this.value;
    }).get();    
    var url="https://homepage";
    if(urgency=="Show All"&&impact=="Show All"&&platform=="Unix,Windows,Network"){
        url="https://homepage";
    }
    if(urgency=="High"&&impact=="Show All"&&platform=="Unix,Windows,Network"){
        url="https://url1";
    }
    if(urgency=="Low"&&impact=="Show All"&&platform=="Unix,Windows,Network"){
        url="http://url2";
    }
    if(urgency=="Show All"&&impact=="Site/Dept"&&platform=="Unix,Windows,Network"){
        url="https://url3";
    }
    if(urgency=="Show All"&&impact=="Multiple Users"&&platform=="Unix,Windows,Network"){
        url="https://url4";
    }
    if(urgency=="Show All"&&impact=="Show All"&&platform=="Unix,Windows"){
        url="https://url5";
    }   
    window.location.href=url;
}
</script>

enter image description here

1
  • This worked as i like. Thanks a alot
    – JunTan
    Commented Dec 12, 2019 at 7:13
1

Try the code below. Let me know if you need any help.

<div>Urgency</div>
<select id="urgencyMenu">
  <option selected="selected">Show All</option>
  <option>High</option>
  <option>Low</option>
</select>
<div>Impact</div>
<select id="impactMenu">
    <option selected="selected">Show All</option>
    <option>Site/Dept</option>
    <option>Multiple Users</option>
</select>
<br>
<div id="platformMenu">
    <div>Platform</div> 
    <input id="platform" checked type="checkbox" name="platform" value="Unix">Unix
    <input id="platform" checked type="checkbox" name="platform" value="Windows">Windows
    <input id="platform" checked type="checkbox" name="platform" value="Network">Network<br><br>
</div>
<input type="button" onsubmit="SubmitClicked()" id="go" value="Submit">


<script>
//function called when submit button is clicked
function SubmitClicked(){
    var urgencyElement = document.getElementById("urgencyMenu");
    var impactElement = document.getElementById("impactMenu");    

    var selectedUrgency = urgencyElement.options[urgencyElement.selectedIndex];

    var selectedImpact = impactElement.options[impactElement.selectedIndex];

    var platformElementChoices = document.querySelectorAll("#platformMenu input[type='checkbox']:checked");

    //function to check checkbox values = unix & windows (this function can be dynamic with some modifications)
    function checkPlatform(platformElementChoices){
        var vw = true;
        for(var i=0;i < platformElementChoices.length; i++){
            var currCheckbox = platformElementChoices[i];
            if(currCheckbox.value != "Network"){
                vw = true;
            }
            else{
                vw = false;
                break;
            }
        }            
        return vw;
    }

    if(selectedUrgency.value == "High" && selectedImpact.value == "Show All" && platformElementChoices.length == 3){
        window.location.href = URL1; //enter url as string between 2 quotes
    }
    else if(selectedUrgency.value == "Low" && selectedImpact.value == "Show All" && platformElementChoices.length == 3){
        window.location.href = URL2; //enter url as string between 2 quotes
    }
    else if(selectedUrgency.value == "Show All" && selectedImpact.value == "Site/Dept" && platformElementChoices.length == 3){
        window.location.href = URL3; //enter url as string between 2 quotes
    }
    else if(selectedUrgency.value == "Show All" && selectedImpact.value == "Multiple Users" && platformElementChoices.length == 3){
        window.location.href = URL4; //enter url as string between 2 quotes
    }
    else if(selectedUrgency.value == "Show All" && selectedImpact.value == "Show All" && checkPlatform(platformElementChoices)){
        window.location.href = URL4; //enter url as string between 2 quotes
    }
    else{
        window.location.href = homepageURL;
    }

}
</script>
4
  • I tried it but it didn't work. I edited the url enclosing it in quotes. But it is not redirecting to the URL i inputted.
    – JunTan
    Commented Dec 8, 2019 at 12:15
  • Is it going in any condition? or redirecting to homepage at least? or is there any error in the browser console? Commented Dec 9, 2019 at 5:30
  • check the updated answer. I had missed the '.href' after 'window.location' Commented Dec 9, 2019 at 5:35
  • Thanks for your help Harshal.
    – JunTan
    Commented Dec 12, 2019 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.