Forum Moderators: open

Message Too Old, No Replies

Submit nameless form

Is it even remotely possible to submit a nameless form?

         

haryanto

1:18 pm on Apr 29, 2004 (gmt 0)

10+ Year Member



Hi guys,

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>

Rambo Tribble

1:39 pm on Apr 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Though I haven't any great expertise with forms, it occurs to me that you may have to have your method specified (get, post) to achieve satisfactory results.

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]

coopster

3:07 pm on Apr 29, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You can access it from it's position in the
document.forms
array:

document.forms[0].submit()

haryanto

5:20 pm on Apr 29, 2004 (gmt 0)

10+ Year Member



Yar but sometimes I get 4 forms on the page so it is not going to work.

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()

haryanto

5:22 pm on Apr 29, 2004 (gmt 0)

10+ Year Member



Oh Yes, can we use this instead?
I tried and it failed......;-(

<form action="action.php">
<a href="javascript:document.this.form.submit();">submit</a>
</form>

john_k

5:26 pm on Apr 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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.

haryanto

9:26 pm on Apr 29, 2004 (gmt 0)

10+ Year Member



But if I have 4 forms on a site that has the same name"myform" would the buttons inside it get confused?

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.

Bernard Marx

9:52 pm on Apr 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's my 2 cents.

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.