Hi,
I’m currently in the process on writing some PHP code that updates a MySQL database from information that was sent from a form. Both the PHP code and the code for the form are on separate pages.
Its all going fine as I have been naming fields on the form and assigning them to PHP variables using $_REQUEST.
However I have a problem with a dynamic feature of my site. I have a series JavaScript functions that dynamically generate text fields with a ‘browse’ button.
I have no idea of how to catch the information that has been generated in each text field in a PHP variable. I have tried all sorts of things, but have had no luck :mad:
My code is:
JavaScript Functions
var form_count = 0;
//add file attachment form and associated elements
function add()
{
//create new <img> element
var new_img = document.createElement('img');
//give element an id
new_img.setAttribute('id', 'child_attachment_img_' + form_count);
//set image source
new_img.setAttribute('src','images/file.png');
//set image alternative text
new_img.setAttribute('alt',' ');
//set image stylings
new_img.setAttribute('style', 'float: left;');
//append newly created element to <span id="content"> tree
document.getElementById('content').appendChild(new_img);
//create new <input> element
var new_attachment = document.createElement('input');
//give element an id
new_attachment.setAttribute('id', 'child_attachment_' + form_count);
//set element type
new_attachment.setAttribute('type', 'file');
//set element size
new_attachment.setAttribute('size', '48');
//append newly created element to <span id="content"> tree
document.getElementById('content').appendChild(new_attachment);
//create new <span> element
var new_text = document.createElement('span');
//give element an id
new_text.setAttribute('id','child_attachment_text_' + form_count);
//set element HTML to produce 'remove' text link
new_text.innerHTML = ' <span class="remove" onclick="remove(' + form_count + ');"> remove</span><br />';
//append newly created element to <span id="content"> tree
document.getElementById('content').appendChild(new_text);
//increase the form count
form_count++;
//if an attachment has been added, change text to "Attach more documentation"
document.getElementById('more').innerHTML = 'Attach more documentation';
}
//remove file attachment form and associated elements
function remove(remove_form_num)
{
//decrease the form count
form_count--;
//remove <input> element attachment
document.getElementById('content').removeChild(document.getElementById('child_attachment_' + remove_form_num));
//remove <span> element text
document.getElementById('content').removeChild(document.getElementById('child_attachment_text_' + remove_form_num));
//remove <img> element image
document.getElementById('content').removeChild(document.getElementById('child_attachment_img_' + remove_form_num));
//if all forms are removed, change text back to "Attach a file"
if (form_count == 0)
{
document.getElementById('more').innerHTML = 'Attach associated documentation';
}
PHP Code:
$cn_nature = $REQUEST["nature"];
$ci_briefdesc = $REQUEST["briefdescription"];
$ci_fulldesc = $REQUEST["fulldescription"];
$cr_fname = $REQUEST["fnameInput"];
$cr_lname = $REQUEST["lnameInput"];
$cd_doc = $REQUEST["add"];
Thanks in advance for any that can help with this problem.