How to Get the FormName and put to a variable

clovismmbr 05 Jan, 2012
Hi GreyHead
I need to get the form name to use in javaScript validation

below i have the model of my validation

alert("Message of Alert here")
document.FormName.ElementName.value="";
document.FormName.ElementName.focus(); 
return false;


All what I need is to get the form name and put the value in my validation

I tried the code:
theForms = document.getElementsByTagName("form");  
for(k=0;k<theForms.length;k++)

and if i try to see like
alert(theForms[k].name);

I can see the name of form
but when i write
alert("Message of Alert here")
document.theForms[k].name.ElementName.value="";
document.theForms[k].name.ElementName.focus(); 
return false;

is return the the Undefined

where am I doing wrong?
Please Help, i Buyed your book but i didnt found nothing about this issue
By the way congratuations for your book, i Learning a lot specialy the barcode into email. Now i can create PromoCodes to my customers
GreyHead 07 Jan, 2012
Hi clovismmbr,

You can set the Form Name as a variable in the Form Javascript box
var formname = '<?php echo $MyForm->formrow->name; ?>';


Bob

PS Personally I'd use the MooTools methods and address the elements using their ids.
clovismmbr 12 Jan, 2012
This works but when I use it I get an error 'undefined'.

I have a specific validation in javascript that i will use in all forms
i think i have to study more javascript.
for a while i am typing the name of the form in each javascript box.
GreyHead 12 Jan, 2012
Answer
Hi clovismmbr ,

Sorry, I missed some quotes :-(

Please try:
var formname = '<?php echo $MyForm->formrow->name; ?>';


Bob
clovismmbr 16 Feb, 2014
Hello Bob, thank you, this solved my issues
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger