[ sojic @ 21.09.2008. 21:29 ] @
Trebam napraviti neki formular, ali hocu da to ne bude klasicni formular sa input boxova, vec da bude text. Kad se klikne "u polje" da se zameni sa input box-a, a kad se "defokusira" da se vrati u span. Nasao sam takvu skriptu, ali jednosmarna. Span pretvara u Input, ali meni treba "dodatak" koji ce, kad se promeni input, i "onblur" da se vrati span. Evo skripte Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Span to Text Box - Demo - DOM</title> <script type="text/javascript"> /* © John Davenport Scheuer */ function exchange(el){ var nodeI=el.parentNode, inputC=document.createElement('input'), text=el.innerHTML; el.style.font='.9em "ms sans serif", "sans"' el.innerHTML+='\x20' with (inputC){ setAttribute('value', text, 0) setAttribute('size', text.length-1, 0) style.width=document.all&&!window.opera? el.offsetWidth-2+'px' : el.offsetWidth+2+'px' setAttribute('type', 'text', 0) setAttribute('id', el.id, 0) setAttribute('readonly', true, 0) } nodeI.replaceChild(inputC, el) } </script> </head> <body> <span id="itm1" onclick="exchange(this)">House</span><br> <span id="itm2" onclick="exchange(this)">SpantoTextBox-Demo</span><br> <span id="itm3" onclick="exchange(this)">Span to Text Box - Demo exchange(this)</span><br> <input id="itm4" type="text" value="Existing Text Box"><br> <span id="itm5" onclick="exchange(this)">In Line Test</span> <span id="itm6" onclick="exchange(this)">In Line Test Too</span> <span id="itm7" onclick="exchange(this)">In Line Test Also</span> </body> </html> |