Jump to content

A question related to CreateElement.. i think


kharbat

Recommended Posts

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]

Link to comment
Share on other sites

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..
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.