Jump to content

Function Looping Problem ?


vmars316
 Share

Recommended Posts

Tia ;

I need more eyes :

Can't figure out my error in 

function SpecificSiteLinks(navigateTo) .

What am I doing wrong , Thanks for your Help...

<!DOCTYPE html>
<html>
<head>
<style>
span.buttons {
  display: inline; /* the default for span */
  padding: 5px;
}
p {
  border: 1px solid blue;  
}
</style>
</head>
<body>
<div style="text-align: center">
    <input type="text" placeholder="Enter URL" id="myInput" value="http://www.google.com">
    <button type="button" onclick="getInputValue()" >Get URL</button>


</div>
<p>
<span class="buttons"><button onclick="WholeSite(0)">duckduckgo.com/</button></span> 
<span class="buttons"><button onclick="SpecificSite(0)">http://vmars.us/SafeBrowser/SafeBrowserHome.html</button></span> 
</p>
<p>
<span class="buttons"><button onclick="WholeSite(1)">pbskids.org/</button></span> 
<span class="buttons"><button onclick="SpecificSite(1)">https://www.infoplease.com/</button></span> 
</p>
<p>
<span class="buttons"><button onclick="WholeSite(2)">.sesamestreet.org/</button></span> 
<span class="buttons"><button onclick="SpecificSite(2)">https://www.youtube.com/watch?v=K1MhFN2Ld30</button></span> 
</p>

<script>
var wholeSiteLinksArray= ["duckduckgo.com", "pbskids.org/", ".sesamestreet.org/"];
var specificSiteLinksArray= ["http://vmars.us/SafeBrowser/SafeBrowserHome.html", 
                              "https://www.infoplease.com/", "https://www.infoplease.com/" , 
							  "https://www.youtube.com/watch?v=K1MhFN2Ld30"];
var NavigateTo = "" ;						  
var SafeSite = false ; 
var arrayPos = 0 ;

function WholeSiteLinks(navigateTo) {
    SafeSite = false ;
    for (var i = 0; i < wholeSiteLinksArray.length; i++) {
        if (wholeSiteLinksArray[i] == navigateTo) {
            SafeSite = true ;
			alert("WholeSiteLinks SafeSite = true   " + "navigateTo = " + navigateTo);
		}else {
            SafeSite = false ;
			alert("WholeSiteLinks SafeSite = false   "+ "navigateTo = " + navigateTo);
            SpecificSiteLinks(navigateTo);
        } 
	}
}

function SpecificSiteLinks(navigateTo) {
    SafeSite = false ;
    for (var i = 0; i < specificSiteLinksArray.length; i++) {
        if (specificSiteLinksArray[i] == navigateTo) {
            SafeSite = true ;
			alert("SpecificSiteLinks SafeSite =  true   " + "navigateTo = " + navigateTo);
		}else {
            SafeSite = false ;
			alert("SpecificSiteLinks SafeSite = false "+ "navigateTo = " + navigateTo);
        }	
    }
}

function WholeSite(arrayPos) {
navigateTo = wholeSiteLinksArray[arrayPos];
alert("function WholeSite(arrayPos) "  + "navigateTo = " + navigateTo);
WholeSiteLinks(navigateTo);
}

function SpecificSite(arrayPos) {
navigateTo = specificSiteLinksArray[arrayPos];
alert("function specificSiteLinks(arrayPos)"  + "navigateTo = " + navigateTo);
SpecificSiteLinks(navigateTo);
}

function getInputValue(){
            // Selecting the input element and get its value 
            var inputURL = document.getElementById("myInput").value;
            // Displaying the value
            alert("function getInputValue()  " + inputURL);
			navigateTo = inputURL ;
            WholeSiteLinks(navigateTo);
    }
</script>

</body>
</html>

 

Link to comment
Share on other sites

function SpecificSiteLinks(navigateTo) {
    SafeSite = false ;
    for (var i = 0; i < specificSiteLinksArray.length; i++) {
        if (specificSiteLinksArray[i] == navigateTo) {
            SafeSite = true ;
			alert("SpecificSiteLinks SafeSite =  true   " + "navigateTo = " + navigateTo);
			break ;
		}else {
            SafeSite = false ;
        }	
    }
		if  (SafeSite == false) { 
			alert("SpecificSiteLinks SafeSite = false "+ "navigateTo = " + navigateTo);
	}
}

Ok , I see it now ,

Thanks

Edited by vmars316
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...