开发者

Javascript Printing HTML but contents not being captured in form

开发者 https://www.devze.com 2023-02-17 09:26 出处:网络
I\'m using this line of JS: document.getElementById(\'nameDiv\').innerHTML = \'<input type=\\\"text\\\" id=\\\"name\\\"/>\';

I'm using this line of JS:

document.getElementById('nameDiv').innerHTML = 
'<input type=\"text\" id=\"name\"/>';

to place a textbox in a d开发者_StackOverflow社区iv called 'nameDiv'. When I hit submit on the form it doesn't seem to pick up the contents of this JS generated text box.

Any ideas?


You must supply a name attribute to have it sent via the POST/GET (without JavaScripting around it, anyway).

document.getElementById('nameDiv').innerHTML = 
'<input type=\"text\" id=\"name\" name=\"some-name\"/>';

I used some-name for example here, you can use the most relevant name.

Also, why are you escaping " when your string delimiter is ' and there will be no clash? I assume this is in a string somewhere.

0

精彩评论

暂无评论...
验证码 换一张
取 消