This is my code:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="jquery-2.2.1.min.js"></script>
<script src="slike.js"></script>
<title>Uvod v jQuery</title>
</head>
<body>
<select id="izberi" onchange="yes()">
<option value="1">Slika 1</option>
<option value="2">Slika 2</option>
<option value="3">Slika 3</option>
<option value="4">Slika 4</option>
</select>
<script>
//without function
var tmp = document.getElementById("izberi");
var izbira = tmp.options[tmp.selectedIndex].value;
if(izbira == 1) {
...
} else if(izbira == 2) {
...
}
//with function
function yes(){
var tmp = document.getElementById("izberi");
var izbira = tmp.options[tmp.selectedIndex].value;
if(izbira == 1) {
...
} else if(izbira == 2) {
...
}
}
</script>
</body>
</html>
In my IF statements I create HTML table, with rows and columns based on what is selected in select. Now if I don't use function ( without onchange in select ) then my code works when I enter the site ( default value of select is 1 ).
But when I select another value for example 2 nothing happens, because my code only executes once ( when I enter the site). Now I tried to fix that with onchange and calling a function ( I have the exact same code in my function ) but if I do that and I select another value my page just goes all white and it looks like my fuction is executing all the time without stop ( the same what happens when the web page is loading )
So where did I make a mistake?
EDIT
I'm using document.write(); to create HTML table while that works when I enter the page it looks like it doesn't work after I select different value and then call the function, that is my problem I think.