views:

673

answers:

1

I have a form with an input type=image. It used to have a confirm in its onclick that returned true/false allowing/stopping the form submit. I've recently 'upgraded' to a non-modal dialog with a callback handler.

Since the callback handler is non-modal, the return value to the input is always false, don't submit... When I submit upon confirmation, the name of the input is not on the form, since it technically wasn't clicked. This is the problem, the code is looking for the input to be on...

I can use a hidden field with the old name and set it to on to bypass that issue, but that seems cludgy. What would be nice, is if I could 'turn the input on' without triggering the onclick (a recursive disaster). Maybe not a disaster, but not sexy. I've tried to set the value of the input to on, but it doesn't seem post.

Any ideas? P.S. I am not using .NET, so solutions involving ASP.NET won't apply :-(

I am adding example code. When clicking Foo!, you'll notice that Foo.x=0 and Foo.y=0 in the address bar. Clicking bar, you get nothing. I'd like to be able to place bar on the form inside the BarCallback.

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <script language="javascript" type="text/javascript">
     function Bar() {
      setTimeout(BarCallback, 500);
      return false;
     }

     function BarCallback() {
      document.getElementById('TheForm').submit();
     }
    </script>
</head>
<body>
    <form method="get" id="TheForm">
     <input type="image" alt="Foo!" name="Foo" />
     <br />
     <input type="image" alt="Bar!" name="Bar" onclick="return Bar();" />
    </form>
</body>
</html>
A: 

What would be nice, is if I could 'turn the input on'

Not possible, sorry. You can only add another control to pretend it was (eg. hidden input, or direct parameter if you're using AJAX).

I've tried to set the value of the input to on, but it doesn't seem post.

How did it fail? For an image input you would need to include .x and .y suffixes to the field name, as that's what browsers do to pass an image click with a position. eg.

<input type="hidden" name="submit.x" value="1" />
<input type="hidden" name="submit.y" value="1" />

the code is looking for the input to be on...

Could you not fix the code to remove that requirement?

bobince
I could, but I'm trying to make the update as painless as possible... The hidden field is working just fine, it just feels dirty. Thanks for the input.
Ben