<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[devshare.de - form-feld zeichen zählen, mehrfach]]></title>
	<link rel="self" href="http://www.devshare.de/feed/atom/topic/41505/"/>
	<updated>2007-12-03T11:01:17Z</updated>
	<generator>PunBB</generator>
	<id>http://devshare.de/topic/41505/formfeld-zeichen-zaehlen-mehrfach/</id>
		<entry>
			<title type="html"><![CDATA[form-feld zeichen zählen, mehrfach]]></title>
			<link rel="alternate" href="http://devshare.de/post/47075/#p47075"/>
			<content type="html"><![CDATA[<p>Folgendes Skript habe ich leicht verändert derzeit im Einsatz um die Anzahl der Eingabezeichen zu zählen und zu begrenzen.</p><p>Benutze ich dieses Skript nur ein mal auf der Seite, alles perfekt.</p><p>Verwende ich das Skript 2 mal oder öfters, funzt es nicht mehr...</p><p>das Skript<br /></p><div class="quotebox"><blockquote><p>var ns6=document.getElementById&amp;&amp;!document.all;<br />function restrictinput(maxlength,e,placeholder) {<br />&nbsp; &nbsp; if(window.event&amp;&amp;event.srcElement.value.length&gt;=maxlength)<br />&nbsp; &nbsp; &nbsp; &nbsp; return false;<br />&nbsp; &nbsp; else <br />&nbsp; &nbsp; &nbsp; &nbsp; if(e.target&amp;&amp;e.target==eval(placeholder)&amp;&amp;e.target.value.length&gt;=maxlength){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var pressedkey=/[a-zA-Z0-9\.\,\/]/; //detect alphanumeric keys<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (pressedkey.test(String.fromCharCode(e.which)))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.stopPropagation();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }<br />function countlimit(maxlength,e,placeholder) {<br />&nbsp; &nbsp; var theform=eval(placeholder);<br />&nbsp; &nbsp; var lengthleft=maxlength-theform.value.length;<br />&nbsp; &nbsp; var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder);<br />&nbsp; &nbsp; if (window.event||e.target&amp;&amp;e.target==eval(placeholder)) {<br />&nbsp; &nbsp; &nbsp; &nbsp; if(lengthleft&lt;0) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; theform.value=theform.value.substring(0,maxlength);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lengthleft=0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; placeholderobj.innerHTML=lengthleft;<br />&nbsp; &nbsp; }<br />function limit(theform,thelimit) {<br />&nbsp; &nbsp; var limit_text=&#039;&lt;small&gt;noch &lt;span id=&quot;&#039;+theform.toString()+&#039;&quot;&gt;&#039;+thelimit+&#039;&lt;/span&gt; Zeichen&lt;/small&gt;&#039;;</p><p>&nbsp; &nbsp; if(document.all||ns6)<br />&nbsp; &nbsp; &nbsp; &nbsp; document.write(limit_text);</p><p>&nbsp; &nbsp; if(document.all) {<br />&nbsp; &nbsp; &nbsp; &nbsp; eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}<br />&nbsp; &nbsp; &nbsp; &nbsp; eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; else if(ns6) {<br />&nbsp; &nbsp; &nbsp; &nbsp; document.body.addEventListener(&#039;keypress&#039;, function(event) { restrictinput(thelimit,event,theform) }, true); <br />&nbsp; &nbsp; &nbsp; &nbsp; document.body.addEventListener(&#039;keyup&#039;, function(event) { countlimit(thelimit,event,theform) }, true); <br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }</p></blockquote></div><p>das Formular (Ausschnitt)</p><div class="quotebox"><blockquote><p>&lt;form id=&quot;form&quot;&gt;<br />&lt;input type=&quot;text&quot; id=&quot;_seokeys&quot; name=&quot;x_seokeys&quot; value=&quot;&quot; /&gt; <br />&lt;script type=&quot;text/javascript&quot;&gt;limit(document.getElementById(&#039;form&#039;).x_seokeys,50)&lt;/script&gt;&lt;br /&gt;</p><p>&lt;input type=&quot;text&quot; id=&quot;_seodesc&quot; name=&quot;x_seodesc&quot; value=&quot;&quot; /&gt; <br />&lt;script type=&quot;text/javascript&quot;&gt;limit(document.getElementById(&#039;form&#039;).x_seodesc,75)&lt;/script&gt;&lt;br /&gt;<br />&lt;/form</p></blockquote></div><p>das Problem<br />Gebe ich in Feld 1 etwas ein, springt die Anzeige des Limit-Platzhalters auf den Wert für Feld 2. Also 75. Weitere Eingaben in Feld1 verändern nichts. Gebe ich etwas in Feld 2 ein, wird nun der Platzerhalter für Feld1 heruntergezählt und aktualisiert. Der Platzhalter f. Feld 2 verändert sich nicht.</p><p>Brauche Hilfe dabei da ich wirklich nicht der JS Spezialist bin. Bemühe mich vor allem diese Kurzschreibweisen zu verstehen aber Feldanzeige. Auf jeden Fall ist mein Wissen nicht so stark dass ich durchbllicke wo da der Fehler ist bzw. wie ich ihn behebe. Das ganze wird ja etwas mit dem ID zu tun haben die den span-Tag zugewiesen wird. Un da werden sich die Beiden vermutlich überschneiden, ich erkenne aber keinen Lösungsweg.</p><p>Danke für die Hilfe</p><br /><p>---------edit----------&gt; solved</p><p>ich hab das skript falsch aufgerufen. der erste parameter &quot;theform&quot; muss als string übermittelt werden und nicht als objekt.</p>]]></content>
			<author>
				<name><![CDATA[yxc86]]></name>
				<uri>http://devshare.de/user/4834/</uri>
			</author>
			<updated>2007-12-03T11:01:17Z</updated>
			<id>http://devshare.de/post/47075/#p47075</id>
		</entry>
</feed>

