Forum Moderators: open
So the question is, how do I get the Invoice # ("os0") in the form below to appear in the section marked ###### -- before submitting the form?
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="email@domain.com">
<input type="hidden" name="item_name" value="Payment: Invoice ######">
<input type="hidden" name="on0" value="Invoice Number(s)">Invoice Number(s): <input type="text" name="os0" maxlength="200">
</form>
<script type="text/javascript">
function fillInvoiceNumber()
{
document.getElementById('item_name').value += document.getElementById('os0').value
return true
}
</script>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="fillInvoiceNumber()">
...
<input type="hidden" name="item_name" id="item_name" value="Payment: Invoice " />
<input type="text" name="os0" id="os0" maxlength="200" />
...
Reading comprehension. I've heard of it.
The question really is, "How can I append/replace a placeholder without using JavaScript?"
I see no way to do that without creating a server-side "router" page. Not much of a big deal. I do it all the time (for pretty much the same reason).
Just create a PHP (or whatever your SS tech is) page that reads the $_POST and creates a new post transaction to the payment server with the strings appended. Some sites do this with user intervention (confirmation pages), which is the easiest, but it can also be done "behind the scenes."
Afterthought ...
I don't usually use onsubmit() on the form element. I typically use an onclick event handler on the actual input element submit button.
I did that for ages until someone pointed out to me that onclick handlers can leave out keyboard navigators, or assistive technology that simulates keyboards.
I haven't been able to test this to make sure it's true, but I started using onsubmit handlers, and I continue to do so.
Is there a problem with this approach? I'm really not sure, and I am asking this in a sincere desire to best serve users.
The
onsubmitevent handler will not respond to a
document.forms[0].submit()method, only in response to an <input type="submit"> button. Somewhere down the line I must have had a notion that I would be safer and not forget this fact in case I was doing anything fancier in my forms processing on the client side outside of using input submit buttons.
As I said, if there is a usability issue then I am clearly unaware and would love to know the correct approach as well.
<WARNING: Content pulled straight from hearsay. No research done. Caveat Emptor>
onclick responds to mouse clicks or simulated mouse clicks, but not to keyboard navigation. They have onkeydown and onkeyup event traps for those.
As people with manual dexterity issues use keyboards more than mice, this may be an issue.
</warning>
However, that onsubmit handler not being called by a JavaScript-triggered submit() is a real problem, and I understand now.
onclickwith alternate non-mouse actions such as the keyboard. You've probably noticed this if you have ever keyed in data in a text box and just pressed enter. The form is submitted. Did an onclick really occur though? Not as far as the definition there goes, I guess.
Perhaps the correct method is to indeed be using the
onsubmithandler as opposed to
onclickat the Submit button input element. Any pre-submission processing can be setup accordingly in the client-side scripting.