views:

149

answers:

1

Problem:
I have a page that has a large form, and in the middle of it I have an image as an input. From that image I get the x and y coordinates for where the user clicked, do some calculation, and redirect to a different page. However when I use Google Chrome on this page I find that the x and y coordinates are not posted, and so this form doesn't work.

Question:
Is this typical behavior of Chrome or am I missing something? If it's a validation problem how can I figure out what the culprit is?

Example:

<form action="FORMACTION" name="MyForm" id="MyForm" method="get">
...
    <input type="image" width="600" height="460" name="graphClick" 
        id="graphClick" src="IMAGESOURCE" alt="IMAGENAME" title="TITLETEXT"
        onclick="goToPage('action');">
...
</form>

Note: goToPage is a javascript function to set the action of the form and submit it.

+1  A: 

It's impossible to tell without seeing what goToPage() does. But setting the form's action on the onclick event sounds kind of weird, and it wouldn't surprise me if that's the reason for the funny behaviour.

I bet if you set an action the normal way, it'll post x and y coordinates.

Maybe the code executed in goToPage could be attached to the onsubmit event of the form? That may increase the chances of the click positions making it through.

Pekka
The graphClick input is not the only input in the form. As a matter of fact there are 9 other inputs and they all submit correctly, so I doubt the javascript is the problem, although I'll try setting a static action for the form and just do a form submit on click.
Robbie
@Robbie Are the 9 other inputs also images?
Pekka
@Pekka no, they are a virity of inputs that aren't images: radio buttons, textfields, checkboxes, ect.
Robbie
@Robbie I think the x and y positions are not making it through because you are fiddling with the `submit` event. You are handling a `click` event and *then* generating the `submit` event in your JavaScript. That the x and y from *before* the submit event are lost wouldn't surprise me. Anyway, it's still just a guess, we'll see when you try out.
Pekka
@Pekka Nope. Changing the form to have a static action, and then using the onClick event of the image to submit the form didn't help any. I'm still not getting my x and y values.
Robbie
@Robbie no, I meant remove the onclick event and have the form submit the normal way (which is the default behaviour of the image form element).
Pekka
@Pekka You were absolutely right the whole time. I still have the onClick event changing the action of the form, but I let the image do the submit instead of using javascript to make the form submit. It works like it has been in all the other browsers now, and it continues to work in the other browsers as well. Thanks a bunch!
Robbie