memo.xight.org

日々のメモ

テストを楽にするための Auto Fill Bookmarklet

Summary

何度も同じ入力する時間が無駄なので
JavaScript で Auto Fill.

ただし,onKeyUp などのイベントが起こらないので注意!

Template

<form>
	<input id="id_name" name="name" />
</form>


javascript:(function(){
	if (document.getElementById(id)){
		function set(id,val){
			document.getElementById(id).value=val;
		}
	}
	set('id_name','value');
}()


Sample

<form>
	<input id="name"     name="name" />
	<input id="mail"     name="mail" />
	<input id="company"  name="company" />
	<input id="position" name="position" />
	<input id="post"     name="post" />
	<input id="zip"      name="zip" />
	<input id="address"  name="address" />
	<input id="tel"      name="tel" />
	<input id="fax"      name="fax" />
	<textarea id="contents" name="contents"></textarea>
</form>

javascript:(function(){
	if (document.getElementById(id)){
		function set(id,val){
			document.getElementById(id).value=val;
		}
	}
	set('name','User Name');
	set('mail','user@example.com');
	set('company','Xight Inc.');
	set('position','Web Solution Group');
	set('post','Sub Leader');
	set('zip','000-0000');
	set('address','Tokyo');
	set('tel','00-1111-2222');
	set('fax','00-1111-3333');
	set('contents',"This is test.\nThis is test.");
}()


追記 [2006-02-14]

cl.pocari.org - 2006-02-13 より
getElementsByName版
javascript:(function(){
	if (document.getElementByName(name)){
		function set(name,val){
			document.getElementByName(name).value=val;
		}
	}
	set('name','value');
}()