Welcome Guest, Not a member yet? Register   Sign In
Using Javascript to set dynamic value for forms
#6

[eluser]boony[/eluser]
Hi,

Well, as stated above, I'm building part of a form dynamically using some javascript. The user enters the number of images to upload into an input field. The script then creates the number of required input fields. Here is the js function to do this.

Code:
function BuildFormFields($num)
  {
    var
      $container = document.getElementById('FormFields'),
     $item, $field, $i;

      $filesnum = $num + 2; //I need to add 2 to this original value and post the new value back to the hidden field
      document.getElementById("filesnum").value = $filesnum;

    $container[removed] = '';
    for ($i = 0; $i < $num; $i++)
    {
      $item = document.createElement('div');
      $item.style.margin = '3px';

      $field = document.createElement('span');
      $field[removed] = 'Image';
      $field.style.marginRight = '10px';
      $item.appendChild($field);

      $field = document.createElement('input');
      $field.name = 'fileupload' + ($i + 3); [b]//this value is not sent to the controller as expected [/b]
      $field.type = 'file';
      $field.className = 'btn'
      $item.appendChild($field);

      $field = document.createElement('span');
      $field[removed] = 'Image caption';
      $field.style.margin = '0px 10px';
      $item.appendChild($field);

      $field = document.createElement('input');
      $field.name = 'caption' + ($i + 3);
      $field.type = 'text';
      $item.appendChild($field);


      $container.appendChild($item);
      // $filesnum = $num + 2;
      // document.getElementById("filesnum").setAttribute("value", $filesnum);
    }

  }

However, when the images are selected and the form submitted the field names or any values created dynamically via the javascript are not passed to the $_POST array. When I test this process in a simple form and post to a simple php file this works as expected. The dynamically created field names and values are passed to the $_POST array and available in the php file.

So, for some reason, CI is not reading the dynamically created field names etc. Why is this so?


Messages In This Thread
Using Javascript to set dynamic value for forms - by El Forum - 04-29-2013, 11:50 PM
Using Javascript to set dynamic value for forms - by El Forum - 04-30-2013, 01:53 AM
Using Javascript to set dynamic value for forms - by El Forum - 04-30-2013, 02:22 AM
Using Javascript to set dynamic value for forms - by El Forum - 04-30-2013, 03:27 AM
Using Javascript to set dynamic value for forms - by El Forum - 04-30-2013, 03:42 AM
Using Javascript to set dynamic value for forms - by El Forum - 04-30-2013, 04:43 AM
Using Javascript to set dynamic value for forms - by El Forum - 05-01-2013, 04:07 AM
Using Javascript to set dynamic value for forms - by El Forum - 05-01-2013, 11:44 PM
Using Javascript to set dynamic value for forms - by El Forum - 05-02-2013, 12:50 AM
Using Javascript to set dynamic value for forms - by El Forum - 05-02-2013, 12:51 AM
Using Javascript to set dynamic value for forms - by El Forum - 05-02-2013, 01:13 AM
Using Javascript to set dynamic value for forms - by El Forum - 05-06-2013, 06:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB