SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Recognizing a Form

    I had created a form as follow:


    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");

    }



    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

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think

    Code:
    myform=document.createElement("formIS");
    
    
    should be

    Code:
    myform=document.createElement("form");

  3. #3
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by samuvk View Post
    myform=document.createElement("form"); is really the name of the form.
    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> ?

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    If you have a form as follows:

    HTML Code:
    <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:

    Code javascript:
    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:

    Code javascript:
    var username = form.element.username.value;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •