<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Little Fox is Learning &#187; defaultValue</title>
	<atom:link href="http://corababy.net/tech/tag/defaultvalue/feed/" rel="self" type="application/rss+xml" />
	<link>http://corababy.net/tech</link>
	<description>People are designed for lots of things, but loneliness isn&#039;t one of them.</description>
	<lastBuildDate>Wed, 24 Mar 2010 16:53:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using jquery to set default value of input box</title>
		<link>http://corababy.net/tech/2009/08/07/using-jquery-to-set-default-value-of-input-box/</link>
		<comments>http://corababy.net/tech/2009/08/07/using-jquery-to-set-default-value-of-input-box/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 15:56:00 +0000</pubDate>
		<dc:creator>little fox</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[defaultValue]]></category>
		<category><![CDATA[inputBox]]></category>

		<guid isPermaLink="false">http://corababy.net/tech/?p=29</guid>
		<description><![CDATA[Well, there are couples of tutorials online to teach us, and also lots of jquery plugin for it. But I feel like I don&#8217;t need that huge functionality for this tiny thing.
So I wrote this one which is just for the little functionality.
Feature:
# default value in input box after page loaded
# on focus,
   [...]]]></description>
			<content:encoded><![CDATA[<p>Well, there are couples of tutorials online to teach us, and also lots of jquery plugin for it. But I feel like I don&#8217;t need that huge functionality for this tiny thing.</p>
<p>So I wrote this one which is just for the little functionality.</p>
<p>Feature:</p>
<p><span style="color: #99ccff;"># default value in input box after page loaded</span></p>
<p><span style="color: #99ccff;"># on focus,</span></p>
<p>   if -> input nothing -> clear to blank,</p>
<p>   else -> keep the previous input value.</p>
<p><span style="color: #99ccff;"># on blur,</span></p>
<p>   if -> input nothing -> back to default value,</p>
<p>   else -> keep the previous input value.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
  &lt;title&gt;default value for text field&lt;/title&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
&nbsp;
  &lt;input type=&quot;text&quot; id=&quot;inputTxt&quot; defaultval=&quot;你在想什么...&quot; /&gt;
  &lt;input type=&quot;button&quot; id=&quot;submitBtn&quot; value=&quot;提交&quot; /&gt;
&nbsp;
  &lt;/body&gt;
  &lt;script&gt;
  $(document).ready(function(){
      var defaulval = $(&quot;#inputTxt&quot;).attr(&quot;defaultval&quot;);
      var checkInputVal;
      $(&quot;#inputTxt&quot;).focus(function(){
        checkInputAval = checkInput(&quot;#inputTxt&quot;, defaulval);
        if (checkInputAval) {
          setToEmpty(&quot;#inputTxt&quot;);
          $(this).css(&quot;color&quot;,&quot;#000&quot;);
        }
      });
&nbsp;
      $(&quot;#inputTxt&quot;).blur(function(){
        checkInputAval = checkInput(&quot;#inputTxt&quot;, defaulval);
        if (checkInputAval) {
          setToDefault(&quot;#inputTxt&quot;, defaulval);
        }
      });
&nbsp;
      setToDefault(&quot;#inputTxt&quot;, defaulval);
  });
  function setToDefault(element, defaulval) {
    $(element).val(defaulval);
    $(element).css(&quot;color&quot;,&quot;#ccc&quot;);
  }
  function setToEmpty(element) {
    $(element).val(&quot;&quot;);
  }
  function checkInput(element, defaulval) {
    if ($.trim($(element).val()).length == 0) {
        return true;
    }
    if ($.trim($(element).val()) == defaulval) {
        return true;
    }
    return false;
  }
  &lt;/script&gt;
&nbsp;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Feel free to let me know if you find some bugs or would like to give some suggestion. :]</p>
<p>It&#8217;s Cora&#8217;s pleasure to get information from all you guys.</p>
<p><span style="color: #ffcc99;">++Cora++</span></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcorababy.net%2Ftech%2F2009%2F08%2F07%2Fusing-jquery-to-set-default-value-of-input-box%2F&amp;linkname=Using%20jquery%20to%20set%20default%20value%20of%20input%20box"><img src="http://corababy.net/tech/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://corababy.net/tech/2009/08/07/using-jquery-to-set-default-value-of-input-box/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
