SuperSal
Programmer
- Mar 13, 2007
- 33
Hi everyone, for some reason the form data from the select boxes are not saving. The code is a bit strange (I apologise) but its just javascript creating the form elements dynamically. here's the code(cut down):
function menu_list ()
{
this.JPEGHighRes = new create_menu("JPEGHighRes"); //video
this.JPEGHighRes.description = "JPEG High";
this.JPEGHighRes.var_type = "Select";
this.JPEGHighRes.size = 40;
this.JPEGHighRes.value = 1;
this.JPEGHighRes.list_desc=new Array("1600x1200", "800x600", "640x480");
this.JPEGHighRes.onchange = "save";
}
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 == "Select")
dstr += render_select(menu_desc[iter]);
if (menu_desc[iter].var_type == "Radio")
dstr += render_radiobutton(menu_desc[iter]);
}
return dstr;
}
function render_select(menu_desc)
{
var dstr="";
dstr += '<tr><td>' + menu_desc.description +'</td><td></td>\n';
dstr += '<td align=center><SELECT name="name_'+ menu_desc.sys_var +'" onchange=' + menu_desc.onchange +' type="select">\n';
for (var iter in menu_desc.list_desc)
{
dstr += '<OPTION VALUE='+iter;
if (menu_desc.value == iter)
{
dstr += ' selected="selected" ';
}
dstr += '>'+menu_desc.list_desc[iter]+'</OPTION>\n';
}
dstr += '</SELECT></td><td></td></tr>\n';
return dstr;
}
function get_formdata(form_data)
{
var theForm = document.forms[0];
var textData = ""
var URL = location.href;
for(i=0; i<theForm.elements.length; i++)
{
if (theForm.elements.value != "") //Not sure whether we need this....do we need to save empty form elements or not?
{
if(theForm.elements.type == "text" || theForm.elements.type == "textarea" || theForm.elements.type == "button" && theForm.elements.onchange == "save")
{
textData += theForm.elements.name + "=" + theForm.elements.value +'&'
}
else if(theForm.elements.type == "checkbox" && theForm.elements.onchange == "save")
{
textData += theForm.elements.name + "=" + theForm.elements.checked +'&'
}
else if(theForm.elements.type == "select" && theForm.elements.onchange == "save")
{
textData += theForm.elements.name + "=" + theForm.elements.options[theForm.elements.selectedIndex].text +'&'
}
}
}
var URL1 = URL+='?'+textData;
var CGIURL = URL1.replace(/\s/g,'+');
var CGIURL1 = CGIURL.slice(0, -1)
alert(CGIURL1);
}
function render_table(title)
{
var dstr="";
var i;
dstr += '<form action="" name="form1">\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> </td><td> </td><td> </td></tr>\n';
dstr += '</table>\n';
dstr += '</form>\n';
return (dstr);
}
var general = new menu_list();
document.write(render_table("Test Table"));
if anyone can see why the select box selection isnt being saved then that would be great.
Cheers
Sally
function menu_list ()
{
this.JPEGHighRes = new create_menu("JPEGHighRes"); //video
this.JPEGHighRes.description = "JPEG High";
this.JPEGHighRes.var_type = "Select";
this.JPEGHighRes.size = 40;
this.JPEGHighRes.value = 1;
this.JPEGHighRes.list_desc=new Array("1600x1200", "800x600", "640x480");
this.JPEGHighRes.onchange = "save";
}
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 == "Select")
dstr += render_select(menu_desc[iter]);
if (menu_desc[iter].var_type == "Radio")
dstr += render_radiobutton(menu_desc[iter]);
}
return dstr;
}
function render_select(menu_desc)
{
var dstr="";
dstr += '<tr><td>' + menu_desc.description +'</td><td></td>\n';
dstr += '<td align=center><SELECT name="name_'+ menu_desc.sys_var +'" onchange=' + menu_desc.onchange +' type="select">\n';
for (var iter in menu_desc.list_desc)
{
dstr += '<OPTION VALUE='+iter;
if (menu_desc.value == iter)
{
dstr += ' selected="selected" ';
}
dstr += '>'+menu_desc.list_desc[iter]+'</OPTION>\n';
}
dstr += '</SELECT></td><td></td></tr>\n';
return dstr;
}
function get_formdata(form_data)
{
var theForm = document.forms[0];
var textData = ""
var URL = location.href;
for(i=0; i<theForm.elements.length; i++)
{
if (theForm.elements.value != "") //Not sure whether we need this....do we need to save empty form elements or not?
{
if(theForm.elements.type == "text" || theForm.elements.type == "textarea" || theForm.elements.type == "button" && theForm.elements.onchange == "save")
{
textData += theForm.elements.name + "=" + theForm.elements.value +'&'
}
else if(theForm.elements.type == "checkbox" && theForm.elements.onchange == "save")
{
textData += theForm.elements.name + "=" + theForm.elements.checked +'&'
}
else if(theForm.elements.type == "select" && theForm.elements.onchange == "save")
{
textData += theForm.elements.name + "=" + theForm.elements.options[theForm.elements.selectedIndex].text +'&'
}
}
}
var URL1 = URL+='?'+textData;
var CGIURL = URL1.replace(/\s/g,'+');
var CGIURL1 = CGIURL.slice(0, -1)
alert(CGIURL1);
}
function render_table(title)
{
var dstr="";
var i;
dstr += '<form action="" name="form1">\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> </td><td> </td><td> </td></tr>\n';
dstr += '</table>\n';
dstr += '</form>\n';
return (dstr);
}
var general = new menu_list();
document.write(render_table("Test Table"));
if anyone can see why the select box selection isnt being saved then that would be great.
Cheers
Sally