<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" > <channel><title>Comments on: Default Text Label in Textbox using JavaScript/jQuery</title> <atom:link href="http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html/feed" rel="self" type="application/rss+xml" /><link>http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html</link> <description>Tutorials, Java, J2EE, Struts, AJAX, JavaScript, CSS, Web 2.0, MySQL, Articles</description> <lastBuildDate>Wed, 08 Feb 2012 10:36:26 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: Viral Patel</title><link>http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html/comment-page-1#comment-18527</link> <dc:creator>Viral Patel</dc:creator> <pubDate>Fri, 09 Dec 2011 17:14:35 +0000</pubDate> <guid isPermaLink="false">http://viralpatel.net/blogs/?p=1800#comment-18527</guid> <description>Hi Prateek, jQuery does provide &lt;a href=&quot;http://viralpatel.net/blogs/2009/12/jquery-live-events.html&quot; rel=&quot;nofollow&quot;&gt;live events&lt;/a&gt; which can be used to map events to any current and future element, but unfortunately &lt;code&gt;live()&lt;/code&gt; does not provide any create method which can be used to handle new element creation. So for now the simplest solution (without adding any additional plugin) would be to wrap above javascript in some &lt;code&gt;function() { }&lt;/code&gt; and call it everytime a new element is added.</description> <content:encoded><![CDATA[<p>Hi Prateek,<br /> jQuery does provide <a href="http://viralpatel.net/blogs/2009/12/jquery-live-events.html" rel="nofollow">live events</a> which can be used to map events to any current and future element, but unfortunately <code>live()</code> does not provide any create method which can be used to handle new element creation. So for now the simplest solution (without adding any additional plugin) would be to wrap above javascript in some <code>function() { }</code> and call it everytime a new element is added.</p> ]]></content:encoded> </item> <item><title>By: Prateek Joshi</title><link>http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html/comment-page-1#comment-18523</link> <dc:creator>Prateek Joshi</dc:creator> <pubDate>Fri, 09 Dec 2011 13:13:02 +0000</pubDate> <guid isPermaLink="false">http://viralpatel.net/blogs/?p=1800#comment-18523</guid> <description>it doesn&#039;t work when we dynamically add the textbox on click of the add-more button. please provide a solution for this.</description> <content:encoded><![CDATA[<p>it doesn&#8217;t work when we dynamically add the textbox on click of the add-more button. please provide a solution for this.</p> ]]></content:encoded> </item> <item><title>By: Kemal</title><link>http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html/comment-page-1#comment-17685</link> <dc:creator>Kemal</dc:creator> <pubDate>Sun, 13 Nov 2011 00:09:55 +0000</pubDate> <guid isPermaLink="false">http://viralpatel.net/blogs/?p=1800#comment-17685</guid> <description>[code language=&quot;js&quot;] $(function () { var searchBox = $(&#039;#&#039;); searchBox.focus(function () { if (searchBox.val() == this.title) { searchBox.removeClass(&#039;text-label&#039;); searchBox.val(&#039;&#039;); } }); searchBox.blur(function () { if (searchBox.val() == &#039;&#039;) { searchBox.addClass(&#039;text-label&#039;); searchBox.val(this.title); } }); searchBox.blur(); }); [/code]</description> <content:encoded><![CDATA[<pre class="brush: jscript; title: ; notranslate">
        $(function () {
            var searchBox = $('#');
            searchBox.focus(function () {
                if (searchBox.val() == this.title) {
                    searchBox.removeClass('text-label');
                    searchBox.val('');
                }
            });
            searchBox.blur(function () {
                if (searchBox.val() == '') {
                    searchBox.addClass('text-label');
                    searchBox.val(this.title);
                }
            });
           searchBox.blur();
        });
    </pre>]]></content:encoded> </item> <item><title>By: Shana</title><link>http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html/comment-page-1#comment-16757</link> <dc:creator>Shana</dc:creator> <pubDate>Mon, 24 Oct 2011 17:10:12 +0000</pubDate> <guid isPermaLink="false">http://viralpatel.net/blogs/?p=1800#comment-16757</guid> <description>Won&#039;t this be an issue when you need to validate required fields, though? If the user submits a form without entering anything, it will submit that default text as the value, so then it won&#039;t properly recognize that the user didn&#039;t fill out the required field. How do you get around this?</description> <content:encoded><![CDATA[<p>Won&#8217;t this be an issue when you need to validate required fields, though? If the user submits a form without entering anything, it will submit that default text as the value, so then it won&#8217;t properly recognize that the user didn&#8217;t fill out the required field. How do you get around this?</p> ]]></content:encoded> </item> <item><title>By: krishn pal</title><link>http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html/comment-page-1#comment-14271</link> <dc:creator>krishn pal</dc:creator> <pubDate>Sat, 05 Mar 2011 13:21:06 +0000</pubDate> <guid isPermaLink="false">http://viralpatel.net/blogs/?p=1800#comment-14271</guid> <description>this field label only for input text like :- Enter user name (for input field)how can i use in password field i change &quot;text&quot; field in passwordit not workingwhat should i doplz help as soon as possible</description> <content:encoded><![CDATA[<p>this field label only for input text<br /> like :- Enter user name (for input field)</p><p>how can i use in password field i change &#8220;text&#8221; field in password</p><p>it not working</p><p>what should i do</p><p>plz help as soon as possible</p> ]]></content:encoded> </item> <item><title>By: thiviya</title><link>http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html/comment-page-1#comment-12991</link> <dc:creator>thiviya</dc:creator> <pubDate>Fri, 13 Aug 2010 05:09:43 +0000</pubDate> <guid isPermaLink="false">http://viralpatel.net/blogs/?p=1800#comment-12991</guid> <description>i have a problem where i call the java script in textbox using .net. pls give me a solution.</description> <content:encoded><![CDATA[<p>i have a problem where i call the java script in textbox using .net. pls give me a solution.</p> ]]></content:encoded> </item> <item><title>By: cem</title><link>http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html/comment-page-1#comment-12867</link> <dc:creator>cem</dc:creator> <pubDate>Sun, 18 Jul 2010 21:40:12 +0000</pubDate> <guid isPermaLink="false">http://viralpatel.net/blogs/?p=1800#comment-12867</guid> <description>Hi, I&#039;am a asp.net user and I want to say someting about your code.Firstly I appreciate you for your simple and chic code.I have been using it very well.But I want  to add some missing code(according to me :)).My Code : [code language=&quot;js&quot;] $(&#039;input[type=&quot;text&quot;]&#039;).each(function(){ if( this.value==this.title){ this.value = $(this).attr(&#039;title&#039;); $(this).addClass(&#039;text-label&#039;);$(this).focus(function(){ if(this.value == $(this).attr(&#039;title&#039;)) { this.value = &#039;&#039;; $(this).removeClass(&#039;text-label&#039;); } });$(this).blur(function(){ if(this.value == &#039;&#039;) { this.value = $(this).attr(&#039;title&#039;); $(this).addClass(&#039;text-label&#039;); } }); } }); [/code] Of Course that&#039;s your code,not mine.But I added oneline,why? After the same page loading, the value of textbox  continue to stand in the textBox.What will be doing is to prevent this problem. So now, after the page loading  your code works very well!</description> <content:encoded><![CDATA[<p>Hi,<br /> I&#8217;am a asp.net user and I want to say someting about your code.Firstly I appreciate you for your simple and chic code.I have been using it very well.But I want  to add some missing code(according to me <img src='http://viralpatel.net/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).My Code :</p><pre class="brush: jscript; title: ; notranslate">
 $('input[type=&quot;text&quot;]').each(function(){
	   if( this.value==this.title){
	        this.value = $(this).attr('title');
	        $(this).addClass('text-label');

	        $(this).focus(function(){
		        if(this.value == $(this).attr('title')) {
			        this.value = '';
			        $(this).removeClass('text-label');
		        }
	        });

	        $(this).blur(function(){
		        if(this.value == '') {
			        this.value = $(this).attr('title');
			        $(this).addClass('text-label');
		        }
	        });
	        }
        });
</pre><p>Of Course that&#8217;s your code,not mine.But I added oneline,why?<br /> After the same page loading, the value of textbox  continue to stand in the textBox.What will be doing is to prevent this problem. So now, after the page loading  your code works very well!</p> ]]></content:encoded> </item> <item><title>By: Ed Cayce</title><link>http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html/comment-page-1#comment-12653</link> <dc:creator>Ed Cayce</dc:creator> <pubDate>Wed, 09 Jun 2010 21:58:02 +0000</pubDate> <guid isPermaLink="false">http://viralpatel.net/blogs/?p=1800#comment-12653</guid> <description>Hey everyone, here is one I made that handles Password inputs as well, and also ignores text boxes with no Title attribute.  You can&#039;t change input types dynamically with all browsers so instead I show and hide two different inputs.  You need one with ID Password and another with ID PasswordDummy,  For clients with no javascript, best to set PasswordDummy to display:none initially.Enjoy.[CODE=&quot;js&quot;]$(&#039;input&#039;).each(function() {if (this.id == &#039;Password&#039;) { // Handle Password differently - it only gets an onblur, in which it gies invisible and activates the PasswordDummy if it is empty// if its blank, make it invisible and Dummy visible if (this.value == &#039;&#039;) { $(this).hide(); $(&quot;#PasswordDummy&quot;).show(); } else { $(this).show(); $(&quot;#PasswordDummy&quot;).hide(); }$(this).blur(function() { if (this.value == &#039;&#039;) { $(this).hide(); $(&quot;#PasswordDummy&quot;).show(); } else { $(this).show(); $(&quot;#PasswordDummy&quot;).hide(); } }); } else if (this.id == &#039;PasswordDummy&#039;) { // Handle Password Dummy differently this.value = $(this).attr(&#039;title&#039;); $(this).addClass(&#039;text-label&#039;);$(this).focus(function() { $(this).hide(); $(&quot;#Password&quot;).show(); $(&quot;#Password&quot;).focus(); }); } else if ($(this).attr(&#039;title&#039;) != undefined) { if (this.value == &#039;&#039;) { this.value = $(this).attr(&#039;title&#039;); $(this).addClass(&#039;text-label&#039;); }$(this).focus(function() { if (this.value == $(this).attr(&#039;title&#039;)) { this.value = &#039;&#039;; $(this).removeClass(&#039;text-label&#039;); } });$(this).blur(function() { if (this.value == &#039;&#039;) { this.value = $(this).attr(&#039;title&#039;); $(this).addClass(&#039;text-label&#039;); } });}});[/CODE]</description> <content:encoded><![CDATA[<p>Hey everyone, here is one I made that handles Password inputs as well, and also ignores text boxes with no Title attribute.  You can&#8217;t change input types dynamically with all browsers so instead I show and hide two different inputs.  You need one with ID Password and another with ID PasswordDummy,  For clients with no javascript, best to set PasswordDummy to display:none initially.</p><p>Enjoy.</p><p>[CODE="js"]</p><p> $(&#8216;input&#8217;).each(function() {</p><p> if (this.id == &#8216;Password&#8217;) {<br /> // Handle Password differently &#8211; it only gets an onblur, in which it gies invisible and activates the PasswordDummy if it is empty</p><p> // if its blank, make it invisible and Dummy visible<br /> if (this.value == &#8221;) {<br /> $(this).hide();<br /> $(&#8220;#PasswordDummy&#8221;).show();<br /> }<br /> else {<br /> $(this).show();<br /> $(&#8220;#PasswordDummy&#8221;).hide();<br /> }</p><p> $(this).blur(function() {<br /> if (this.value == &#8221;) {<br /> $(this).hide();<br /> $(&#8220;#PasswordDummy&#8221;).show();<br /> }<br /> else {<br /> $(this).show();<br /> $(&#8220;#PasswordDummy&#8221;).hide();<br /> }<br /> });<br /> }<br /> else if (this.id == &#8216;PasswordDummy&#8217;) {<br /> // Handle Password Dummy differently<br /> this.value = $(this).attr(&#8216;title&#8217;);<br /> $(this).addClass(&#8216;text-label&#8217;);</p><p> $(this).focus(function() {<br /> $(this).hide();<br /> $(&#8220;#Password&#8221;).show();<br /> $(&#8220;#Password&#8221;).focus();<br /> });<br /> }<br /> else if ($(this).attr(&#8216;title&#8217;) != undefined) {<br /> if (this.value == &#8221;) {<br /> this.value = $(this).attr(&#8216;title&#8217;);<br /> $(this).addClass(&#8216;text-label&#8217;);<br /> }</p><p> $(this).focus(function() {<br /> if (this.value == $(this).attr(&#8216;title&#8217;)) {<br /> this.value = &#8221;;<br /> $(this).removeClass(&#8216;text-label&#8217;);<br /> }<br /> });</p><p> $(this).blur(function() {<br /> if (this.value == &#8221;) {<br /> this.value = $(this).attr(&#8216;title&#8217;);<br /> $(this).addClass(&#8216;text-label&#8217;);<br /> }<br /> });</p><p> }</p><p> });</p><p>[/CODE]</p> ]]></content:encoded> </item> <item><title>By: Greg</title><link>http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html/comment-page-1#comment-12606</link> <dc:creator>Greg</dc:creator> <pubDate>Thu, 27 May 2010 20:19:42 +0000</pubDate> <guid isPermaLink="false">http://viralpatel.net/blogs/?p=1800#comment-12606</guid> <description>Any ideas on how this could be made to work with a password input?</description> <content:encoded><![CDATA[<p>Any ideas on how this could be made to work with a password input?</p> ]]></content:encoded> </item> <item><title>By: Md. Lutfor Rahman</title><link>http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html/comment-page-1#comment-12522</link> <dc:creator>Md. Lutfor Rahman</dc:creator> <pubDate>Wed, 05 May 2010 21:22:02 +0000</pubDate> <guid isPermaLink="false">http://viralpatel.net/blogs/?p=1800#comment-12522</guid> <description>I had need this for deperture tracing system</description> <content:encoded><![CDATA[<p>I had need this for deperture tracing system</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: viralpatel.net @ 2012-02-09 10:01:02 -->
