javascript - js function not changing value -


i have following code. first time function called iframe changes contents newpage second time function called page doesn't change.

<!doctype html> <html>    <head> <meta charset="iso-8859-1"> <title>submit</title>  <script>     var url = 1;     function seturl(url){        var win1 = "http://localhost/audio/src/submit1.html" ;        var win2 = "http://localhost/audio/src/newpage.html";               if (url === 1){                      document.getelementbyid('iframe').src=win2;          url=2;                  }                     else{            document.getelementbyid('iframe').src=win1;             url=1;        }     }     </script>   </head>   <body>  <iframe src="http://localhost/audio/src/audio.html" style="width:0;height:0;border:0; border:none;"></iframe>    <iframe id="iframe" style="border:0; "   src="http://localhost/audio/src/submit1.html">     </iframe>    <input type="button" value="click me 71"  onclick="seturl(url)">    </body> </html> 

you have 2 variables called url.

the 1 defined global , 1 defined function argument.

your function changes 1 defined function argument, isn't preserved anywhere.

if want modify global one: don't define argument in function definition (and don't bother passing argument function).


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -