Let's step through your code ... line by line. You can easily do that with pen & paper.
Please try to reproduce the steps
1 - Click single mode button ... so mode will be 'single'
2 - Oh, you initialize count with a string. Why? You should use this
3 - Click on the first button. This method will be called
generate_url('data input by php')
so the first parameter "selection" of the method generate_url is 'data input by php'
4 - Inside generate_url() the first if statement will be true (because mode=='single'), so you go on with this part of the method
5 - You increase count by 1 ... so count == 1 now
6 - Now you add the "selection" to the url
7 - if count == 1 (this is true) you change window.location.href which results in an immediate page refresh
In 'dual' mode
4 - The first if will be false
5 - The second if will be true, because mode=='dual'
6 - count is still 0, so the first if will be true
7 - you copy "selection" to "selection_1" and increase count by 1 (so count == 1)
8 - the second if is true ... but IS STILL WRONG because you are using the assignment operator "=" instead of the comparison operator "==". This will set count to 1 and the result of the if condition is true
9 - you copy "selection" also to "selection_2" and increase count by 1 (so count == 2)
10 - The third if is also true because count==2, so you append both copies of "selection" to the url and immediately refresh the browser because you change window.location.href