Jump to content

Function Looping Problem ?


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 post
Share on other sites

"keeps looping?" How many times does it loop? Your code as written sends as many alerts as there are sites in specificSiteLinksArray

Link to post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...