Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting the value of a form item 1

Status
Not open for further replies.

SuperSal

Programmer
Mar 13, 2007
33
Hi everyone, ok this is a bit strange the way its been done so bare with me! I am dynamically creating menu items and need to create a save function to save the values of form items on the server only I cannot seem to access the values of the dynamically created form items and I'm not sure why. The code is as follows:

this.SysName = new create_menu( "SysName"); //general
this.SysName.description = "System Name";
this.SysName.var_type = "Alpha";
this.SysName.size = 40;
this.SysName.readonly = false;
this.SysName.value = "DM00D0D9181716";
this.SysName.onchange = true;

function render_alpha(menu_desc)
{
var dstr="";
dstr += '<tr><td>' + menu_desc.description +'</td><td></td>\n';
dstr += '<td align=center><input type="text" size=' + menu_desc.size +' value="' + menu_desc.value +'" id=name_'+ menu_desc.sys_var +'" name="name_'+ menu_desc.sys_var +'"';
if (menu_desc.readonly)
dstr += "READONLY";
dstr += '></td></tr>\n';

return dstr;
}

function render_multi_menu(menu_desc)
{
var dstr="";

for (var iter in menu_desc)
{
if (menu_desc[iter].var_type == "Alpha")
dstr += render_alpha(menu_desc[iter]);
if (menu_desc[iter].var_type == "Checkbox")
dstr += render_checkbox(menu_desc[iter]);
if (menu_desc[iter].var_type == "Numeric")
dstr += render_numeric(menu_desc[iter]);
if (menu_desc[iter].var_type == "Combo")
dstr += render_combo(menu_desc[iter]);
if (menu_desc[iter].onchange == true)
save_settings(menu_desc[iter]);
}
return dstr;
}

function render_table(title)
{
var dstr="";
var i;

dstr += '<form action="">\n';
dstr += '<table>\n';
dstr += '<tr><td></td><td><FONT SIZE=+1 FACE="Arial"><b>' + title + '</b></font></td></tr>\n';
dstr += render_multi_menu(general);
dstr += '<tr><td>&nbsp</td><td>&nbsp</td><td>&nbsp</td></tr>\n';
dstr += '</table>\n';
dstr += '</form>\n';
return (dstr);
}

var general = new menu_list();

document.write(render_table("Test Table"));

function get_formdata()
{
var data = document.name_SysName.value; //this not getting the value

alert(data);

I am running the get_formdata() function from the onUnload method.

Thanks
Sally
 
[tt]You are using document.name_SysName.value[/tt] - the correct format for retrieving a text field value is [tt]document.formName.fieldName.value[/tt]

Give your form a name and use the format I described.

Adam
 
Hi Adam, thanks for replying, I did actually try that but it still didn't work. Do you think its something to do with the fact that the tables being rendered rather than just through html?

Sally
 
Thanks Adam after a closer look I had put 2 form tags in...one when rendering the table and one then one in when rendering the object. i took out the form tag in the object then gave the other form a name and referenced it how you suggested.

Ta

Sally
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top