[FX.php List] FMSkipRecords

DC dan.cynosure at dbmscan.com
Tue Mar 28 09:31:22 MST 2006


Thanks for the feedback and suggested refinements to this javascript 
"links submit forms" approach!

I thought that the javascript:void(0) was necessary to get IE to process 
the JS. I'm pretty sure I researched/tested this, but I didn't take 
notes on the testing so I can't immediately say something clever like 
"if you leave out the void() call then IE 6.0.3.45rev42 breaks and 17 
people in the world are using that browser and I want to support them."

instead, i relied on rumors at the old internet to give me the scoop:
http://ajaxian.com/archives/ie-frame-bug

That has a discussion of using void versus a dummy URI and it looks like 
the dummy URI wins. so, based on all the input about dropping void() 
perhaps this would be better:

<FORM NAME="sub" METHOD="POST" ACTION="file1.php">
<input type="hidden" id="data" name="data" value="mydata">
</FORM>
<a href="file2.php"
ONCLICK="document.sub.submit(); return false;"
target="_blank">LINK TEXT HERE</a>

This design has the benefit of actually falling back to a clickable link 
if JS is not available - so it degrades gracefully.

Kevin, the onsubmit button approach gives you a button - not a text 
link. So, if you are looking for a page full of grey buttons then use 
the standard form element button. But, if you want actual text links to 
submit forms and carry POST data along you have to do this little 
javascript dance. And yes, javascript is required - so if you want your 
script to degrade gracefully, you'd better have some kind of fallback 
like an a href tag.

Finally, if you want to be completely standards compliant (and not just 
hack a few form-submitting links together for a one-off) you probably 
want to check out the 'behaviour.js' library to get 'clunky' javascript 
out of HTML altogether.

http://bennolan.com/behaviour/

thanks for the lively discussion - i feel quite edified.
dan

Kevin Futter had written:
> On 28/3/06 10:19 AM, "Kevin Futter" <kfutter at sbc.melb.catholic.edu.au>
> wrote:
> 
> 
>>On 28/3/06 9:46 AM, "Steve Hannah" <shannah at sfu.ca> wrote:
>>
>>
>>>On 27-Mar-06, at 2:23 PM, Kevin Futter wrote:
>>>
>>>
>>>>><FORM NAME="sub" METHOD="POST" ACTION="file.php">
>>>>><input type="hidden" id="data" name="data" value="mydata">
>>>>></FORM>
>>>>><a href="javascript:void(0)"
>>>>>ONCLICK="document.sub.submit(); return false;"
>>>>>target="_blank">LINK TEXT HERE</a>
>>>>>
>>>>>This puts a simple form (add hidden elements for any data that you
>>>>>want
>>>>>to shepherd into the next form submission) right before the link that
>>>>>will use it. Tested in Safari, Firefox (Mac), and IE6.
>>>>>
>>>>>Cheers,
>>>>>dan
>>>>
>>>>Just a quick note about the JavaScript here: please avoid the
>>>>"javascript:"
>>>>pseudo protocol; it's invalid and clunky,
>>>
>>>Not sure in what way this is invalid.
>>>Clunky?  Sounds like personal taste (although  many web developers
>>>share this personal taste).
>>>
>>>
>>>
>>>>and in your example, not even
>>>>necessary. The "return false" should be sufficient.
>>>
>>>True
>>>
>>>>Of course, the form will
>>>>fail completely if JS is disabled or unavailable.
>>>>
>>>>Additionally, if you're going to use hrefs, they should point a
>>>>legitimate
>>>>URI. If no such thing exists for your purpose, then you can simply
>>>>use the
>>>>onclick handler on a more appropriate element, such as <span> or
>>>>even <p>.
>>>
>>>I agree with the spirit of this comment (not using the wrong tag for
>>>the wrong job), but in this case an <a href> is the most appropriate
>>>tag because this IS a link.  You click it, and it takes you to
>>>another page.  Clearly this is NOT a paragraph (p) and it is not just
>>>a span of text ... it is a link and thus should be represented by an
>>>href.
>>
>>Actually, technically it's not a link as it doesn't contain or point to a
>>valid URI. It's simply a mechanism to make the thing "clickable", and JS
>>does the rest - it's just a JavaScript trigger. Why not just use a standard
>>"submit" button, with an onclick handler in the form attributes? eg:
>>
>><FORM NAME="sub" METHOD="POST" ACTION="file.php" onclick="jsFunction();
>>return false;">
>>...
>><input type="submit" value="Button Title">
>>...
>></form>
>>
>>This is a much more standards-friendly approach, and pretty much how it
>>should be done these days.
> 
> 
> Replying to my own post here, but the JS handler in the form attributes
> should of course be "onsubmit"!
> 
> D'Oh!
> 


More information about the FX.php_List mailing list