tjohnson_nb Posted May 5, 2010 Share Posted May 5, 2010 Not sure if anyone can help here - this involves javascript and php. I have a simple javascript like this; function disp_confirm(companyid) { var link='companies.php?action=Archive&companyid='+companyid; var c=confirm('Do you really want to archive this company?'); if (c==true) { document.location.href=link; } } And further in the php code I have; echo " <input type=\"image\" src=\"../b_drop.png\" onclick=\"disp_confirm('$companyid')\">\n"; When you click on the image (b_drop.png) the confirmation box comes up but when you click 'ok' the _GET variables in the javascript link are not passed to the server but for some reason the coordinates of where you clicked the image are?? I get this output from the $_POST variable but nothing from the $_GET variable and I'm not posting anything. companyid=6668 fields=Array x=8 y=6 Of course if I click on different spots of the image I get different numbers for x and y. Quote Link to comment https://forums.phpfreaks.com/topic/200826-strange-posting-error/ Share on other sites More sharing options...
siric Posted May 5, 2010 Share Posted May 5, 2010 I moved around the code a bit as function disp_confirm(companyid) { var c = confirm('Do you really want to archive this company?'); if (c == true) { var link='companies.php?action=Archive&companyid='+companyid; alert(link); } } The alert shows that the correct url is passed to link variable. It would be just a matter of getting that into the URL. Quote Link to comment https://forums.phpfreaks.com/topic/200826-strange-posting-error/#findComment-1053785 Share on other sites More sharing options...
siric Posted May 5, 2010 Share Posted May 5, 2010 Ok, Have done some further research and have come up with this so far. The main problem seems to be the image for the form button. If you do not use an image and use window.location, it works. function disp_confirm(companyid) { var c = confirm('Do you really want to archive this company?'); if (c == true) { var link='companies.php?action=Archive&companyid='+companyid; window.location=link; //could also be // window.location = 'companies.php?action=Archive&companyid='+companyid; } } and html echo "<input type='button' value='Redirect' onclick=\"disp_confirm('$companyid')\">"; Will chk further on the image as button option. Quote Link to comment https://forums.phpfreaks.com/topic/200826-strange-posting-error/#findComment-1053804 Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 try this: echo ' <input type="image" src="../b_drop.png" onclick="disp_confirm(\''.$companyid.'\')"> \n'; Quote Link to comment https://forums.phpfreaks.com/topic/200826-strange-posting-error/#findComment-1053807 Share on other sites More sharing options...
siric Posted May 5, 2010 Share Posted May 5, 2010 Tested this and it works. <script type='text/javascript'> function disp_confirm(companyid) { var c = confirm('Do you really want to archive this company?'); if (c == true) { window.location.href = 'companies.php?action=Archive&companyid='+companyid; } } </script> <? $companyid = '1'; echo "<input type='image' src='blue.png' onclick=\"disp_confirm('$companyid')\" />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/200826-strange-posting-error/#findComment-1053812 Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 so the code I posted didn't work then? Quote Link to comment https://forums.phpfreaks.com/topic/200826-strange-posting-error/#findComment-1053815 Share on other sites More sharing options...
tjohnson_nb Posted May 5, 2010 Author Share Posted May 5, 2010 Ok, Have done some further research and have come up with this so far. The main problem seems to be the image for the form button. If you do not use an image and use window.location, it works. function disp_confirm(companyid) { var c = confirm('Do you really want to archive this company?'); if (c == true) { var link='companies.php?action=Archive&companyid='+companyid; window.location=link; //could also be // window.location = 'companies.php?action=Archive&companyid='+companyid; } } and html echo "<input type='button' value='Redirect' onclick=\"disp_confirm('$companyid')\">"; Will chk further on the image as button option. Yes that works so I guess I don't need to use the image. The really strange thing is I have the exact same code running in another file (actually several) with that image and they all work! Mystery Quote Link to comment https://forums.phpfreaks.com/topic/200826-strange-posting-error/#findComment-1053852 Share on other sites More sharing options...
siric Posted May 5, 2010 Share Posted May 5, 2010 so the code I posted didn't work then? Yes, yours the HTML was fine, but i changed the javascript as well. Quote Link to comment https://forums.phpfreaks.com/topic/200826-strange-posting-error/#findComment-1053893 Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 so the code I posted didn't work then? Yes, yours the HTML was fine, but i changed the javascript as well. showoff Quote Link to comment https://forums.phpfreaks.com/topic/200826-strange-posting-error/#findComment-1053894 Share on other sites More sharing options...
siric Posted May 6, 2010 Share Posted May 6, 2010 showoff Far from!!! I had to do some serious research and coding for that - I am NOT!!! a JS expert!! Quote Link to comment https://forums.phpfreaks.com/topic/200826-strange-posting-error/#findComment-1053907 Share on other sites More sharing options...
Muddy_Funster Posted May 6, 2010 Share Posted May 6, 2010 It was just a joke dude Quote Link to comment https://forums.phpfreaks.com/topic/200826-strange-posting-error/#findComment-1053910 Share on other sites More sharing options...
siric Posted May 6, 2010 Share Posted May 6, 2010 It was just a joke dude I know...but thanks for the thumbs up!!! Quote Link to comment https://forums.phpfreaks.com/topic/200826-strange-posting-error/#findComment-1053911 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.