Recognizing a Form

I had created a form as follow:

[COLOR=“#0000FF”]function makeForm() {

mypara=document.getElementById(“paraID”);
myform=document.createElement(“formIS”);
myselect = document.createElement(“select”);

theOption=document.createElement(“OPTION”);
theText=document.createTextNode(“Revenue”);
theOption.setAttribute(“value”,“Revenue”);
theOption.appendChild(theText);
myselect.appendChild(theOption);

theOption=document.createElement(“OPTION”);
theText=document.createTextNode(“Expenses”);
theOption.appendChild(theText);
theOption.setAttribute(“value”,“Expenses”);
myselect.appendChild(theOption);

myform.appendChild(myselect);
mypara.appendChild(myform);
myselect.onchange=TitleOnChange;
mybreak=document.createElement(“p”);
myform.appendChild(mybreak);

myform.setAttribute(“id”,“formIS”);

}[/COLOR]

I had identified the form with and id: myform.setAttribute(“id”,“formIS”);

Now I would like to identify my form to apply an IF instruction: something like:


myform=document.getElementById(“formIS”);
if (myform == “formIS”)

I tried all the following options and none worked. Does anyone knows why?

if (myform.id == “formIS”)
if (myform.id.value == “formIS”)

I also tried to debug the code and this is what I see when I put the mouse over myform –> formis#formIS

Thanks you very much

I think

[COLOR=#0000FF]myform=document.createElement("formIS");

[/COLOR]

should be

[COLOR=#0000FF]myform=document.createElement("form");[/COLOR]

myform=document.createElement(“form”); is really the name of the form.

Both ways works the same.

However, I changed and tested and the result is the same.

Thanks

but you said

I had created a form as follow:

The argument you pass to createElement() is the name of the element type, not the value of the name attribute you want the element to have.

If you are treating the argument as the name attribute, then how do you expect createElement to know whether to create a div, p, form or whatever other element with the name you are passing?

Do you want to create a <form> or <formIS> ?

If you have a form as follows:


<form id="loginUser" action="login.php">
    <p><label>Username: <input name="username"></label></p>
    ...
</form>

Your script would gain a reference to that form with:


var form = document.getElementById('loginUser');

Please do not place a name attribute on the form tag itself. Name attributes should only be used on form controls, for identification when they are submitted, and so that you can access them from a script with:


var username = form.element.username.value;