Okay
So I changed a couple things and this is what I have got:
Code:
<div onclick="generate_url('data input by php')">A button</div>
<div onclick="generate_url('different data)">A different button</div>
<div class="view_mode" onclick="change_mode('single')">Singular</div>
<div class="view_mode" onclick="change_mode('dual')">Dual</div>
<script>
var mode="single";
var count = 0;
// Function to change view mode (working)
function change_mode(newmode)
{
mode = newmode;
count=0;
}
//Standard url that users selections are added to
var standard_url='http://www.mywebsite.com/page.php?id=';
// Function to generate a url or mutiple url's based off user input
function generate_url(selection)
{
//Allow user to choose a single option
if (mode=='single')
{
count++;
var singular_url=standard_url+selection;
if (count==1)
{
window.location.href = singular_url;
}
}
//Dual
if (mode=='dual')
{
if (count==1)
{
var selection_2=selection;
count++;
}
if (count==0)
{
var selection_1=selection;
count++;
}
if (count==2)
{
dual_url=selection_1+selection_2;
window.location.href = dual_url;
}
}
}
</script>
So I fixed a couple of things, the count is now declared and assigned a variable not a string.
I also fixed the if(count==1) statement so it's not using an assignment.
I moved the if(count==1) statement above the if(count==0) statement so it would only activate the second time around.
Previously it would add the first user input twice into the url.
I am trying to get it so on the first click of one button it adds the first value dependent on what button the user clicked and on the second click it then adds a second user input and creates a url.
Which then javascript sends the user too.
I now have the problem where it creates the following url
mywebsite.com/whatever?id=undefined(SECOND INPUT)
It should give the following
mywebsite.com/whatever?id=(FIRST INPUT)(SECOND INPUT)
I think it's to do with the variables not being passed from one loop to the next.
I am really a Javascript newbie. If you could help me get this working I would much appreciate it.