Forum Moderators: open
I have hundreds of forms to modify so I am unable to change each of them one by one.
My forms are all nameless.
Usually the code for submission is
<a href="javascript:document.formname.submit();">submit</a>
BUt since my forms are nameless(not my fault actually) I would like to know if there is any convenient avenue to submit it. I tried the method below but it doesn't work.
Will anyone please help?!
<form action="action.php">
<a href="javascript:submit();">submit</a>
</form>
An on-event handler placed within the form tags should be able to pass the form to a function using the "this" keyword. Example <a href="" onclick="yourFunction(this.form);">
[edited by: Rambo_Tribble at 3:26 pm (utc) on April 29, 2004]
I have like hundreds of form buttons to modify and I was thinking of using one code for all so I don't have to spend the whole night changing it.
>>You can access it from it's position in the >>document.forms array:
>>document.forms[0].submit()
One other thought - hundreds of forms might seem like a lot, but just plodding through to search for "<form" on all pages and then giving them names should still only take an hour or two. Probably about the same (or less) than the time it takes to find and apply a different method.
e.g. on one page:
<body>
<form name="myform" action="action1.php">
<a href="javascript:document.myform.submit();">submit</a>
</form>
<br>
<form name="myform" action="action2.php">
<a href="javascript:document.myform.submit();">submit</a>
</form>
<br>
<form name="myform" action="action3.php">
<a href="javascript:document.myform.submit();">submit</a>
</form>
<br>
</body>
========================================
Standard form elements (buttons, checkboxes, etc.) have a .form property, so if you used a button instead, then this.form.submit() would work. I don't know if a link within a form has that property or not.
One other thought - hundreds of forms might seem like a lot, but just plodding through to search for "<form" on all pages and then giving them names should still only take an hour or two. Probably about the same (or less) than the time it takes to find and apply a different method.
IF the forms you have are like that, specifically:
1. The code in the handler is always: javascript:document.myform.submit();
2. The form is always the parent element of the link (not grandparent etc)
then you have to simply swap:
javascript:document.myform.submit();
for
javascript:this.parentElement.submit();
I had to do changes like this on a similar scale before.
I used TextPad, but a lot of decent editors will have this facility.
1. Dump ALL the files into a new instance of the editor app.
2. Do a global search & replace (Find in files)
- Best to go for the whole tag to be safe.
3. Save all.
I managed to get it down to around 15 seconds (don't ask).
---------------------------
..but that would be irresponsible. Hardly covering one's ass, is it?
Search under "<form ", and click on all instances in the results page one by one, and name them all.