Jump to content

Strange posting error


tjohnson_nb

Recommended Posts

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.  :P

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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')\" />";
?>

 

 

Link to comment
Share on other sites

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  :confused:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.