anmartinez Posted February 8, 2006 Share Posted February 8, 2006 Hello,I have a html form, and I use a image like a button. When somebody click this image, the browser redirect you to other page. This is the code:<a href="java script:enviar()"><img name="boton" src="/pasarelatpv/img/gr_pagar.gif" border="0"></a>The function "enviar()", redirect to other page, when the image is clicked. This is the code:var pulsado = false;function enviar(){ if (!pulsado) { pulsado = true; document.pago.submit(); }}I use the variable "pulsado" to indicate that the image has been clicked, and if someone click on this image again, happen nothing. But, it isn´t work fine. If somebody click on this image again, the process of redirect to another page fail, is stop.What can I do?. I want, that the efect of click on the image, only occur the first time. The rest of time, this "image-button", happen nothing.Thanks. Regards. Link to comment Share on other sites More sharing options...
Chocolate570 Posted February 8, 2006 Share Posted February 8, 2006 Hmmm... I don't think you can declare global variables in javascript. Not sure. So use this code.First, put this in the body: <input type="hidden" id="pulsado" value="false" /> Then, put this as your function: function enviar(){x=document.getElementById("pulsado").valueif (x!="true"){x="true"document.pago.submit();}} Hope that helps. Link to comment Share on other sites More sharing options...
scott100 Posted February 8, 2006 Share Posted February 8, 2006 What can I do?. I want, that the efect of click on the image, only occur the first time. The rest of time, this "image-button", happen nothing.<{POST_SNAPBACK}> Hi,This should do what you need, it will only open a new page once then after that will not work.<head><script>var showMe=true; //global variablefunction check(){if(showMe==true)window.open ('http://www.google.com', 'newwindow', config='height=500,width=600,toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, directories=yes, status=yes')showMe=false;}</script></head><body><img onclick="check()" name="boton" src="/pasarelatpv/img/gr_pagar.gif" style="border: 0px solid green" /></body> Link to comment Share on other sites More sharing options...
aspnetguy Posted February 8, 2006 Share Posted February 8, 2006 Hmmm... I don't think you can declare global variables in javascript.You can use global variables in JavaScript. Link to comment Share on other sites More sharing options...
anmartinez Posted February 8, 2006 Author Share Posted February 8, 2006 You can use global variables in JavaScript. <{POST_SNAPBACK}> Thanks Scott, your code help me. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now