Jump to content

Recommended Posts

Hi all

 

I'm generating a checkbox using

 

  var cellRightSel = row.insertCell(4);
  var sel = document.createElement("input");  
  sel.className = 'formfield';
  sel.name = 'daycare' + iteration;
  sel.type = "checkbox";  
  sel.checked = false;
  cellRightSel.appendChild(sel);

 

if I use

 

  sel.onclick = function(){ alert('clicked')}

 

then I can get it to display an alert message when clicked.

 

Is it possible to change that so when clicked, it would dynamically display two blank text fields rather than the alert message?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/176616-javascript-tickbox-on-click/
Share on other sites

Yes. Are you wanting to dynamically create those text boxes or do the textboxes already exist but in a hidden state? Personally, I always prefer to create elements in a hidden state than to create them dynamically as you have done above.

 

Whatever the case you can either define the process to create/display those checkboxes when defining that dynamic function

 sel.onclick = function()
{
    //Insert code to create text boxes
}

 

Or you can create the function independently and then assign the onclick to that function

function createBoxes()
{
    //Insert code to create text boxes
}

sel.onclick = createBoxes;

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.