Tag Archive for input

Using Input Title As Initial Text – Hide When On Focus

function watermark ($obj) {
				
	var prev;
	
	$obj.each(function() {
		if ($(this).attr("title"))	$(this).val($(this).attr("title")).addClass("greyout");
	});
	
	$obj
		.focus(function()
			{
				if ($(this).val()==$(this).attr("title")) {
					prev = $(this).val();
					$(this).val("").removeClass("greyout");
				}
			})
		
		.blur(function()
			{
				if($(this).val()=="") {
					$(this).val(prev).addClass("greyout");;
				}
			});

}

source

MOOTOOLS JS – Clear input field onClick onFocus on click focus active

// 201004291250 - Mootools clear input on focus, return default value if no data entered
// FROM:  Clear text field with mootools on focus. - MooTools Users | Google Groups <a href="http://bit.ly/cHPev3" >http://bit.ly/cHPev3</a>

/* 
	I've got this snippet that will clear the value on focus and if the value of 
	the focus is '' it will put the default value again in the input. You will 
	need the default value to be on an attribute of the input, like alt or 
	anyother (if you don't bother about validation). 
	
	Fábio Miranda Costa 
	Engenheiro de Computação 
	<a href="http://meiocodigo.com" >http://meiocodigo.com</a> 

*/

// FUNCTION: 

Element.implement({ 
    clearFocusResetBlur: function(attr){ 
        var valueString = this.get(attr); 
        this.addEvents({ 
            'focus': function(){ 
                if( this.get('value') == valueString ) this.set('value',''); 
            }, 
            'blur': function(){ 
                if( this.get('value') == "" ) this.set('value',valueString); 
            } 
        }); 
    } 
}); 


// Usage
// HTML: 
// <input id="input_id" value="some value" alt="default value" /> 


// JS: 
$('.jform form .cleardefault').set('alt','value').clearFocusResetBlur('alt');

source

Get value from a radio button in Jquery

$("input[name='radioname']:checked").val();

source

How to change dynamically input type password to show description inside field

/***********************************************************
* txReplaceFormPassword.js
*
* Written by Simone Lippolis - <a href="http://simonelippolis.com" >http://simonelippolis.com</a>
*
* This script is distributed under a Creative Commons - Commercial, Attribution licence
* <a href="http://creativecommons.org/licenses/by/2.5/it/" >http://creativecommons.org/licenses/by/2.5/it/</a>
*
* Feel free to copy, edit, redistribute this script. Please, don't remove credits.
*
* If you find some bug or error, please let me know.
*
* How to use:
*
* 1. Include jquery:
* &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
*
* 2. Include this script:
* &lt;script type="text/javascript" src="txReplaceFormPassword.js"&gt;&lt;/script&gt;
*
* 3. On document ready, invoke the plugin
*
* $(document).ready(function () {
* &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;$('#pwd').txReplaceFormPassword({
*&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;show_text : 'Password'
*&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;});
* &nbsp;&nbsp; &nbsp;});
*
* consider '#pwd' as the object which needs to be replaced:
*
* &lt;form action="someaction" method="post" id="formid" name="formname"&gt;
*&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;input type="password" name="pwd" id="pwd" value="" /&gt;
*&nbsp;&nbsp; &nbsp;&lt;/form&gt;
*
* The 'show_text' parameters contains the text to be shown in password's
* text field.
*
***********************************************************/

jQuery.fn.txReplaceFormPassword = function(options) {
 var options = jQuery.extend( {
 show_text: 'Password'
 },options);

 function trim(txt) {
 return txt.replace(/^s+|s+$/g, '');
 }

 return this.each(function() {
 if (jQuery(this).val().length == 0) {

 var $pos = jQuery(this).position();
 var $style = jQuery(this).attr('style');
 var $class = jQuery(this).attr('class');
 var $size = jQuery(this).attr('size');
 var $id = jQuery(this).attr('id');
 var $name = jQuery(this).attr('name');

 jQuery(this).hide();
 jQuery(this).after('&lt;input type="text" id="txgrpl-' + $id + '" name="txgrpl-' + $name + '" size="' + $size + '" style="' + $style + '" value="' + options.show_text + '" rel="' + $id + '" title="' + options.show_text + '" /&gt;');

 $('#txgrpl-' + $id).focus(function() {
 $(this).hide();
 var $id = $(this).attr('rel');
 $('#' + $id).show().focus();
 });
 }

 jQuery(this).blur(function() {
 if (trim(jQuery(this).val()) == '' || jQuery(this).val() == undefined) {
 var $id = jQuery(this).attr('id');
 jQuery(this).hide();
 $('#txgrpl-' + $id).show();
 }
 });
 });
};

source

Gives all inputs a class name of their type

$('input').each(function() {
    var inputType = $(this).attr('type');   
    $(this).addClass(inputType);
  });

source

Set Focus to the Next Input Field with jQuery

$.fn.focusNextInputField = function() {
	return this.each(function() {
		var fields = $(this).parents('form:eq(0),body').find('button,input,textarea,select');
		var index = fields.index( this );
		if ( index > -1 && ( index + 1 ) < fields.length ) {

			fields.eq( index + 1 ).focus();
		}
		return false;
	});
};

source

Get rid of annoying line breaks in multiline input fields

inputField.autoKern = FALSE

source

Stores the name to a string variable and displays it.

x = raw_input("Enter name: ")
print "Hey " + x
raw_input("Press<enter>")

source

jQuery proper search clear

$("#searchText").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});

source

jQuery – Add/Focus/Blur Input Value

$(function(){
  
        $('input[type="text"]').each(function(){
          if(this.value==''){this.value='Enter Value'}
        });
        
        $('input[type="text"]').focus(function(){
          if(this.value=='Enter Value'){this.value=''}
        });
       
        $('input[type="text"]').blur(function(){
          if(this.value==''){this.value='Enter Value'}
        });

  });

source