html - Page doesn't work good in JavaScript code with form -
i write (the full code) code @ javascript.
in line 6 wrote code:
div_new = div_new+"<form name='"+name+"' onsubmit="+ return refresh(name, url, document.forms[name][name].value , '', '', 'refresh'); +" method='post' style='display:inline;'>";
when add code, page didn't work good.
i believe have problem quotes of onsubmit
, because when delete ' onsubmit' works good.
if write full code in regular html (not in js) works good.
what should solve problem?
the full code:
function chat(mem_id) { count++; var div_new = "<div style='position:absolute; width:200px; bottom:0px; left:10px;'>"; div_new = div_new+"<div style='width:100%; background-color:green;'>top "+ mem_id +" - "+count+"</div>"; div_new = div_new+"<div style='width:100%; height:300px; background-color:pink;'>bottom // refresh_chat"+ mem_id +" "; var name = "send_chat_"+mem_id; var url = "send_chat.php"; div_new = div_new+"<form name='"+name+"' onsubmit="+ return refresh(name, url, document.forms[name][name].value , '', '', 'refresh'); +" method='post' style='display:inline;'>"; div_new = div_new+"<textarea name='"+name+"' autofocus=autofocus placeholder='"+name+"'></textarea><input type=submit value=' send '>"; div_new = div_new+"</form>"; div_new = div_new+"</div>"; div_new = div_new+"</div>"; bottom = div_new; document.getelementbyid('bottom').innerhtml = bottom; }
please see demo here
there several mistakes in line
div_new = div_new+"<form name='"+name+"' onsubmit="+ return refresh(name, url, document.forms[name][name].value , '', '', 'refresh'); +" method='post' style='display:inline;'>";
use code
function chat(mem_id) { count++; var div_new = "<div style='position:absolute; width:200px; bottom:0px; left:10px;'>"; div_new = div_new+"<div style='width:100%; background-color:green;'>top "+ mem_id +" - "+count+"</div>"; div_new = div_new+"<div style='width:100%; height:300px; background-color:pink;'>bottom // refresh_chat"+ mem_id +" "; var name = "send_chat_"+mem_id; var url = "send_chat.php"; div_new = div_new+"<form name='"+name+"' onsubmit=\"return refresh(" + name +","+ url+",document.forms[name][name].value , '', '', 'refresh');\" + method='post' style='display:inline;'>"; div_new = div_new+"<textarea name='"+name+"' autofocus=autofocus placeholder='"+name+"'></textarea><input type=submit value=' send '>"; div_new = div_new+"</form>"; div_new = div_new+"</div>"; div_new = div_new+"</div>"; bottom = div_new; document.getelementbyid('bottom').innerhtml = bottom; }
the main issue because of return not part of string because of double quote , need use escape sequence
this correct solution
div_new = div_new+"<form name='"+name+"' onsubmit=\"return refresh(" + name +","+ url+",document.forms[name][name].value , '', '', 'refresh');\" + method='post' style='display:inline;'>";
i added same escape sequence here
Comments
Post a Comment