- 爱易网页
-
JavaSript
- javascript创建的textarea在表单提交时不上传,而其它的input text可以解决方案
日期:2014-05-16 浏览次数:20488 次
javascript创建的textarea在表单提交时不上传,而其它的input text可以
页面中选择一个JPG文件后,JavaScript创建一组的表单项,其它的都正常,就是新产生的textarea不行,请问大家怎么解决这个问题?
页面如下:
------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<HTML>
<HEAD>
<%@ page
language= "java "
contentType= "text/html; charset=GB18030 "
pageEncoding= "GB18030 "
%>
<META http-equiv= "Content-Type " content= "text/html; charset=GB18030 ">
<META name= "GENERATOR " content= "IBM WebSphere Studio ">
<TITLE> test.jsp </TITLE>
</HEAD>
<BODY>
<SCRIPT language=JavaScript>
var photonum=1;
function newInputFile()
{
photonum ++;
var ptab = document.getElementById( "photoTable ");
if(!ptab) return;
var newRow = ptab.insertRow(-1);
var c1 = newRow.insertCell(-1);
tmpStr = "Headline <br> ";
tmpStr += " <INPUT type=\ "text\ " name=\ "Headline " +photonum + "\ " size=\ "80\ "> <BR> ";
tmpStr += "Caption <br> ";
tmpStr += " <TEXTAREA rows= '10 ' cols= '80 ' name= 'Caption " + photonum + " '> </TEXTAREA> <BR> ";
//tmpStr += " <input type= 'text ' name= 'caption ' size= '80 '> <br> ";
tmpStr += "Choose Image File: <INPUT type=\ "file\ " name=\ "InputFile ";
tmpStr += photonum + "\ " id=\ "InputFile " + photonum;
tmpStr += "\ "size=\ "40\ " onchange=\ "inputFileChange( ' " + photonum + " ')\ " ";
tmpStr += "> ";
c1.innerHTML = tmpStr;
var c2 = newRow.insertCell(-1);
tmpStr = " <IMG border=\ "0\ " src=\ "images/preview.jpg\ " width=\ "283\ " name=\ "previewImg "+ photonum;
tmpStr += "\ " id=\ "previewImg " + photonum+ "\ "> ";
c2.innerHTML = tmpStr;
}
function inputFileChange(index_pix){
var i = parseInt(index_pix,10);
var fileName = document.getElementById( "InputFile "+index_pix);
if(!fileName || !fileName.value) return;
var img = document.getElementById( "previewImg "+index_pix);
var patn= /\.jpg$|\.jpeg$/i;
if(patn.test(fileName.value)){
img.setAttribute( 'src ', 'file://localhost/ ' + fileName.value);
if(i == photonum) newInputFile();
} else {
alert( "JPG file please ");
img.setAttribute( 'src ', 'images/preview.jpg ');
}
}