kharbat Posted June 13, 2006 Share Posted June 13, 2006 i have a form and button..when button is clicked a text filed appears in the form..how can i get this done?? Quote Link to comment Share on other sites More sharing options...
nogray Posted June 13, 2006 Share Posted June 13, 2006 It depends how you set it up, but the easiest will be something like this[code]<table><tr id="hidden_field_tr" style="display:none;"><td><input type="text" /></td></tr></table><button onclick="document.getElementById('hidden_field_tr').style.display='';">Show</button><button onclick="document.getElementById('hidden_field_tr').style.display='none';">Hide</button>[/code] Quote Link to comment Share on other sites More sharing options...
kharbat Posted June 13, 2006 Author Share Posted June 13, 2006 thanks for that... but in fact i want to create the text field.. i mean that i don't want it to be pre defined because i don't know how many text fields gonna be created in the page.. you got my point?i need a script that creates a text field from nothing.. and puts it within a specific form and that's all.. Quote Link to comment Share on other sites More sharing options...
nogray Posted June 13, 2006 Share Posted June 13, 2006 you can do something like this[code]<script language="javascript"> function create_element(){ var form_tbody = document.getElementById('form_tbody'); var n_tr = document.createElement("TR"); var n_td = document.createElement("TD"); var n_input = document.createElement("INPUT"); n_input.name = "input_name"; n_input.id = "input_id"; n_input.type = "text"; form_tbody.appendChild(n_tr); n_tr.appendChild(n_td); n_td.appendChild(n_input); } </script><table> <tbody id="form_tbody"> <tr><td><input type="text" /></td></tr> </tbody></table>[/code]Just remmeber that you need to tbody if you are using tables. Quote Link to comment Share on other sites More sharing options...
kharbat Posted June 13, 2006 Author Share Posted June 13, 2006 i am not using tables actually.. but your script was pretty helpful.. i will try it and tell you what happens Quote Link to comment Share on other sites More sharing options...
kharbat Posted June 13, 2006 Author Share Posted June 13, 2006 now what's wrong with this script ? [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /] [code]<script language="javascript">file = document.createElement("INPUT");file.name = "t1";file.type = "text";forms = document.getElementById('form1');form.appendChild(file);</script><form id="form1" name="form1" method="post" action=""> <label> <input type="button" name="Button" value="Button" /> </label></form>[/code] Quote Link to comment Share on other sites More sharing options...
nogray Posted June 14, 2006 Share Posted June 14, 2006 You are creating the input field before the page loads, the javascript cannot find the forms because it haven't loaded yet. You'll need to set your script as a function and call it when the page loads.(btw you are missing an s in your form.appendChild(file)- should be forms) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.