Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-22-2012, 01:55 AM   PM User | #1
glycerides
New to the CF scene

 
Join Date: Jan 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
glycerides is an unknown quantity at this point
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..
glycerides is offline   Reply With Quote
Old 01-22-2012, 06:59 AM   PM User | #2
glycerides
New to the CF scene

 
Join Date: Jan 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
glycerides is an unknown quantity at this point
is this question hard??or lacking explanation/sense
glycerides is offline   Reply With Quote
Old 01-22-2012, 08:24 AM   PM User | #3
cuzMazn
New Coder

 
Join Date: Dec 2011
Location: Earth if you want to know
Posts: 27
Thanks: 0
Thanked 3 Times in 3 Posts
cuzMazn is an unknown quantity at this point
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._
cuzMazn is offline   Reply With Quote
Users who have thanked cuzMazn for this post:
glycerides (01-27-2012)
Old 01-27-2012, 01:41 AM   PM User | #4
glycerides
New to the CF scene

 
Join Date: Jan 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
glycerides is an unknown quantity at this point
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.
glycerides is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:18 PM.


Advertisement
Log in to turn off these ads.