views:

153

answers:

4

I'm trying to modify the code from this script. Basically I'm trying to get the script to send the browser to another page rather than display the results in a div.

This is the code in question:

<script type="text/javascript">
function openOneSlot() {
SpinningWheel.addSlot({1: 'First', 2: 'Second'});

SpinningWheel.setCancelAction(cancel);
SpinningWheel.setDoneAction(done);

SpinningWheel.open();
}

function done() {
var results = SpinningWheel.getSelectedValues();
document.getElementById('result').innerHTML = 'values: ' + results.values.join(' ') + '<br />keys: ' + results.keys.join(', ');

}

function cancel() {
document.getElementById('result').innerHTML = 'cancelled!';
}


window.addEventListener('load', function(){ setTimeout(function(){ window.scrollTo(0,0); },     100); }, true);
</script>

I've changed the 'done' function to as follows:

function done() {
var results = SpinningWheel.getSelectedValues();


if (SpinningWheel.getSelectedValues() == "1,First") 
{  
window.location="first.html";
}
else if (SpinningWheel.getSelectedValues() == "2,Second") 
{  
window.location="second.html";
}
else
{
alert("Damn, Still not working..");
}

But now I'm lost as I'm very new to javascript.. Can anyone help the noob to get this working? :)

A: 

Try location.href instead of window.location

Note that this particular thing (changing page) is done differently across different browsers so you should google "javascript redirect " if you run into trouble on a particular browser

laura
A: 

Look at what is returned by SpinningWheel.getSelectedValues(). It is an object with two properties keys and values. Therefore, it will not equal "1,First". Check into what is in those properties, and base your conditionals on those.

geowa4
A: 

To pass your variables through, use the following syntax:

window.location = "first.html?var1Name=" + var1 + "&var2Name=" + var2;

To get the value of those variables on your first.html and second.html pages, you can use the window's query string to get hold of their values:

http://www.eggheadcafe.com/articles/20020107.asp

You would want to look at the window.location.search property.

Ian Kemp
A: 

Try this:

function done() {
var results = SpinningWheel.getSelectedValues();

if (results.values[0] == "First") 
{  
   window.location.href="first.html";
}
else if (results.values[0] == "Second") 
{  
   window.location.href="second.html";
}
else
{
   alert("Damn, Still not working..");
}

The returned values appear to be an array of all the slots. Since yours has only one slot, I'm only looking at the first array position of the "results.values" array.

Joe D
Thank you kind sir! That's got it working perfectly.
Finne