Discuss Number of forms on a page in the JavaScript Development forum on Dev Shed. Number of forms on a page JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
Posts: 488
Time spent in forums: 3 Days 2 h 42 m 16 sec
Reputation Power: 29
Number of forms on a page
is there an easy way to find out how many forms there are on a page?
what i want to do is change the onsubmit attribute of ALL my forms, but in such a way that i can easily change it again, so i was thinking along the lines of:
Code:
for(var a = 0; a < document.forms.length; a++) {
document.forms[a].onsubmit = 'return false;';
}
this is probably way off the mark, but i cant think of another way of doing it.
__________________
Xaphan
Have I helped you? Then help me, and click the rep. button, top right ()
Posts: 488
Time spent in forums: 3 Days 2 h 42 m 16 sec
Reputation Power: 29
ok, now i have this, its almost working... BUT.
Code:
function page_load()
{
for(var a = 0; a < document.forms.length; a++)
{
document.forms[a].onSubmit = "alert('Please submit the form correctly by clicking the appropriate button.');return false;";
}
}
i put the onload directly into the HTML body tag.
this is not actually setting the onsubmit attribute for the forms, as the alert is not appearing, and the form is submitting.
this works if i hard-code it into the <form> tag, but not by this javascript.
am i missing something quite simple? i've been at this for the best part of 90 mins now... lol.
Posts: 488
Time spent in forums: 3 Days 2 h 42 m 16 sec
Reputation Power: 29
like this?
Code:
function page_load()
{
for(var a = 0; a < document.forms.length; a++)
{
document.forms[a].onsubmit=function()
{
alert('Please submit the form correctly by clicking the appropriate button.');
return false;
}
}
}
i was trying different ways of writing onsubmit to see if it made a difference.