Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

handling 2 forms with the same name on 1 document 1

Status
Not open for further replies.

chriss87

Programmer
Jan 29, 2007
11
PL
hi all

i have a little problem with operating on a web document - it has got two forms with the same name: something like:

Code:
(...)
<form name="form1" method="post" action=[action1]>
<input type="submit" name="submit" value="button1" id="button">							

</form>								
(...)
<form name="form1" method="post" action=[action2]>

<input name="Submit" value="button2" id="button" type="submit">

</form>		
(...)

i've created an IE.app object
and when i want to have one button clicked i use

Code:
oIE.document.all.form1.Submit.Click

but since there are 2 buttons called submit, and two form1's anything i try to do just seems to consider the first button (even though its name is written with only lower case letters)

my question is how could i emphesise which form or button my action should consider?

thanks in advance
 
[1] >i have a little problem with operating on a web document - it has got two forms with the same name
It is an abominable thing to do!

[2] Stop naming type="submit" button "submit". It is no good.
[tt]
<!-- etc etc -->
<input name="[red]anythingotherthan[/red]Submit" value="button1" id="button" type="submit">
<!-- etc etc -->
<input name="[red]anythingotherthan[/red]Submit" value="button2" id="button" type="submit">
<!-- etc etc -->
[/tt]
[3] >my question is how could i emphesise which form or button my action should consider?
>oIE.document.all.form1.Submit.Click
[tt]
'all is not needed
'first form
oIE.document.form1[blue](0)[/blue].[red]anynameotherthanSubmit[/red].Click
'second form
oIE.document.form1[blue](1)[/blue].[red]anynameotherthanSubmit[/red].Click
[/tt]
[3.1] If you don't really have some onsubmit handler attached to the forms or that you want to bypass it, you can simply script it like this.
[tt]
'first form
oIE.document.form1[blue](0)[/blue].submit
'second form
oIE.document.form1[blue](1)[/blue].submit
[/tt]
You can see it the button is named submit, the above is absolutely ambiguous to debug.
 
I know that putting two forms with the same name in one document or using <input type="submit"> are very nasty habbits - but i wanted to have my script work even on those

Tried putting indeces before but i guess i made some errors
Works perfectly now :)

Thanks
 
If you want to use submit as name on the submit button, by all means use the form of reference to it in this format:
[tt] document.form1(0).elements("submit").click[/tt]
What I am opposing is not the scripter's "will" to use certain name - people can want whatever they want and design their language to make it legitime, it is that one has to know what are the reserved words (happen to all languages) to claim one really knows a language; and what is the name collision which makes itself a big issue of namespace. Naming "submit" is not an ultimate impass of this language - though some might be - no, but it is no good if one does not know what are the consequences.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top