Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    HOw to add attributes to dynamic form

    hello Sir/Mam

    i have a piece of code here that creates a dynamic form..

    Code:
    <script type='text/javascript' language='javascript'>
    	<!-- 
    function createTextbox(){
    	var textboxtag = document.createElement("input");
    		textboxtag.setAttribute("name","username");				   
            document.getElementById("form1").appendChild(textboxtag);
    					
    				}
    -->
    </script>
    
    <body>
    <div id='div1'>
              <button name='textbox' onclick='createTextbox()'>Textbox</button>
    </div>
    <div id='div2'>
         <form id='form1' action='#' method='post'>
              
         </form>
    </div> 
    </body>
    this code sets the "name" attribute to "username" automatically..
    my problem is how to set the name attribute manually by the user after the dynamic textbox is created..

    just like in visual basic where after you create a form e.g button or textfield, theres a side pane where you can change attributes like name, value, etc..

    tnx for the time reading my post..sorry for my poor explanation of the problem..im new in javascript and trying to learn it all by myself..

  • #2
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    is this question hard??or lacking explanation/sense

  • #3
    New Coder
    Join Date
    Dec 2011
    Location
    Earth if you want to know
    Posts
    27
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by glycerides View Post
    is this question hard??or lacking explanation/sense
    Hi Glycerides,

    I can understand your problems, except this one:

    "...my problem is how to set the name attribute manually by the user after the dynamic textbox is created..."

    I am not sure I understand your question, can you make it more clearly so that I can help?

    Regards,

    Tim._

  • Users who have thanked cuzMazn for this post:

    glycerides (01-27-2012)

  • #4
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks Sir Tim for reading my post..

    Ill try to explain my problem as clearly as i can..

    Code:
    textboxtag.setAttribute("name","username");
    this code above will set the attribute of the textbox after i created it using createElement.

    so the dynamic form source code will become like this:
    Code:
    <input type='text' name='username'>
    but what i want is after i create the dynamic textbox using createElement and i click it i can set its name to what ever i want.

    maybe like this:
    Code:
    textboxtag.onClick = function setAttributeManually(){
                                //maybe here the setting of attribute will take place
                                // but i dont know how..
         }
    i dont know if it clear enough now.but i wish it was..
    thanks again..more power to the readers.


  •  

    Posting Permissions

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