SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question location.href not working!!

    Can anyone tell me why the following code is not working please?
    The function is called when a user clicks a button.

    Code:
    function goToStock(){
    	if (document.getElementById("top_search").value=="used") {
    		window.location.replace='http://www.mysite.co.uk/used-cars/';
    	}
    	else if (document.getElementById("top_search").value=="van") {
    		window.location.replace='http://www.mysite.co.uk/used-vans-trucks/';
    	} 
    	else if (document.getElementById("top_search").value=="bike") {
    		window.location.replace='http://www.mysite.co.uk/used-bikes/';
    	} 
    	else if (document.getElementById("top_search").value=="nearlynew") {
    		window.location.replace='http://www.mysite.co.uk/nearly-new-cars/';
    	} 
    	else if (document.getElementById("top_search").value=="motability") {
    		window.location.replace='http://www.mysite.co.uk/motability/';
    	} 
    }

  2. #2
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    I've been having a look at some other coding and I can get this to work if I put the url into the select option value. Problem is I need to have another value in there to get the rest of the coding to work on the page.
    Can anyone tell me how to modify the code below so that I can check to see what value has been selected in the dropdown and then assign a url accordingly?

    The code is below. Any help would be greatly appreciated with this.

    Code:
    <script type="text/javascript">
    function goTo() {
    var sE = null, url;
    if(document.getElementById) {
    sE = document.getElementById('urlList');
    } else if(document.all) {
    sE = document.all['urlList'];
    }
    if(sE && (url = sE.options[sE.selectedIndex].value)) {
    location.href = url;
    }
    }
    </script>
    
    
    <select id="urlList" size="1">
    <option value="">Select a link...</option>
    <option value="http://www.google.com/">Google</option>
    <option value="http://www.mozilla.org/">Mozilla.org</option>
    <option value="http://www.opera.com/">Opera.com</option>
    </select>
    <input type="button" value="Go!" onclick="goTo();">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •