kev wood Posted June 9, 2008 Share Posted June 9, 2008 i have set up a page with some button on which load different pages up. the buttons are held within a form and the target is set to blank. this part is fine for the first set of buttons but i need one of them to reload the page but stay in the same window. the code that is getting used at the minute looks like this <input name="reset" type="image" onclick="broad.php" src="admin/images/reset_btn.gif" /> // this is the button i need to refresh the page in same window <form id="buttons" method="post" enctype="multipart/form-data" action="<?php echo $PHP_SELF; ?>" target="_blank"> // the code for the form function changeAction(ins) {var form1 = document.getElementById('buttons'); if(ins==0) form1.action = "broad_prev.php"; if(ins==1) form1.action = "broad_send.php"; if(ins==2) form1.action = "broad.php" ; form1.submit(); } is it possible to get the button to refresh the page without opening a new window? Quote Link to comment Share on other sites More sharing options...
hansford Posted June 9, 2008 Share Posted June 9, 2008 this will just reload the page, but any and all info will be lost if(ins==3) window.location.href="http://www.yourdomain.com/thispage.html"; Quote Link to comment Share on other sites More sharing options...
kev wood Posted June 9, 2008 Author Share Posted June 9, 2008 thanks for the reply it is resetting all the fields on the page but it keeps opening a new window. the form is set up with the target="_blank" so after each button is clicked it opens a new window. is there away to get it to ignore this and load the page in the same window or will it have to have come sort of a close window to stop this from happening. Quote Link to comment Share on other sites More sharing options...
hansford Posted June 9, 2008 Share Posted June 9, 2008 remove: target="_blank" Quote Link to comment Share on other sites More sharing options...
kev wood Posted June 9, 2008 Author Share Posted June 9, 2008 i need the target blank in there the other buttons need to open up a new window Quote Link to comment Share on other sites More sharing options...
hansford Posted June 9, 2008 Share Posted June 9, 2008 How about this: function changeAction(ins) {var form1 = document.getElementById('buttons'); if(ins==0) form1.action = "broad_prev.php"; if(ins==1) form1.action = "broad_send.php"; if(ins==2) form1.action = "broad.php" ; if(ins==3){ window.location="http://www.yourdomain.com/yourpage.php"; return; //exits function doesnt allow form1.submit() to get executed } form1.submit(); } Quote Link to comment Share on other sites More sharing options...
kev wood Posted June 10, 2008 Author Share Posted June 10, 2008 no that didnt work either. would it be possible to create another form inside the other one and set the target to self so it does not open a new window when the button is clicked. would the function be able to be duplicated or would the not work. if my code was like this would it work? <input name="preview" type="image" value="preview" onclick="changeAction(0)" src="admin/images/preview_btn.gif" alt="Preiview your Layout" align="left" /> <br /> <br /> <input align="left" name="send2" type="image" src="admin/images/test_btn.gif" alt="Send mailout" /> <br /> <br /> <input align="left" name="send" type="image" onclick="changeAction(1)" src="admin/images/list_btn.gif" alt="Send mailout" /> <br /> <br /> <form id="button" method="post" enctype="multipart/form-data" action="<?php echo $PHP_SELF; ?>" target="_blank"> <input name="reset" type="image" onclick="broad.php" src="admin/images/reset_btn.gif" /> </form> function changeAction(ins) {var form1 = document.getElementById('buttons'); if(ins==0) form1.action = "broad_prev.php"; if(ins==1) form1.action = "broad_send.php"; form1.submit(); } the above code for the change action would be for all the other button and this one below would be for the button which has been put in its own form function changeAction(ins) {var form2 = document.getElementById('button'); if(ins==0) form2.action = "window.location.reload()"; form1.submit(); } Quote Link to comment Share on other sites More sharing options...
hansford Posted June 10, 2008 Share Posted June 10, 2008 just get rid of target="_blank" in the form; then when your function is called add it if you want another window open like: form1.target="_blank"; Quote Link to comment Share on other sites More sharing options...
kev wood Posted June 10, 2008 Author Share Posted June 10, 2008 i have gone down a different road now it would not work that way and i was coming close to punching the comp. i have still used a form but it now loads a page which removes all the files and then redirects the user to the page they where on to start with. Quote Link to comment Share on other sites More sharing options...
hansford Posted June 10, 2008 Share Posted June 10, 2008 lol been there, done that-will be there again and again. I feel your frustration. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.