...

View Full Version : HOw to add attributes to dynamic form



glycerides
01-22-2012, 02:55 AM
hello Sir/Mam

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



<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
01-22-2012, 07:59 AM
is this question hard??or lacking explanation/sense

cuzMazn
01-22-2012, 09:24 AM
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._

glycerides
01-27-2012, 02:41 AM
Thanks Sir Tim for reading my post..

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


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:

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

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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum