Some useful effects code for form (form) _ Form effects

Source: Internet
Author: User
Code that limits only what is write-qualified
The ENTER key allows the cursor to move to the next input box: <input onkeydown= "if (event.keycode==13) event.keycode=9" > <br>
Can only be Chinese: <input onkeyup= "Value=value.replace (/[-~]/g,") "onkeydown=" if (event.keycode==13) event.keycode=9 "> <br>
can only be in English and numbers. Blocked Input method: <input style= "ime-mode:disabled" onkeydown= "if (event.keycode==13) event.keycode=9" > <br >
can only input in English and number: <input onkeyup= "Value=value.replace (/[\w]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ') "onkeydown=" if (event.keycode==13) event.keycode=9 "> <br >
Can only be digital <input onkeyup= "Value=value.replace (/[^\d]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ') "><br>
Can only display, can not modify the text box <input readOnly value= "can only show, cannot modify" >
Only digits in input can be prompted when submitting
<script language=javascript>
function Onlynum ()
{
if (!) ( (event.keycode>=48&&event.keycode<=57) | | (event.keycode>=96&&event.keycode<=105) | | (event.keycode==8)))
Event.returnvalue=false;
}
</script>
<input onkeydown= "Onlynum ();" >
Drop-down list opens a window when you select a connection, a new window pops up
<select onchange= "If" (This.selectedindex && this.selectedindex!=0) {window.open (this.value);} this.selectedindex=0; " >
<option selected> More Links ......</option>
<option value= "Http://www.jb51.net";>cnbruce</option>
<option value= "Http://www.21west.net";>daonet</option>
<option value= "http://www.blueidea.com"; >blue!dea
</select>
A check box, click on the next set of check boxes are all selected
<input type= "checkbox" Name= Checka "onpropertychange=" for (i=0;i<a.children.length;i++) {a.children.checked= this.checked} ">a
<br>
<span id= "A" >
<input type= "checkbox" Name= "A1" >
<input type= "checkbox" Name= "A2" >
<input type= "checkbox" Name= "A3" >
</span>
option in Select to Classify list
<span style= "position:absolute;border:1px inset #d3d6d9" ><select style= "MARGIN:-2PX; width:200px ">
<option selected>------------Please select------------</option>
<optgroup label= "Javascript&vbscript District" >
<option> Original
<option> Classic
<optgroup label= "Backstage Area" >
<option>asp&sql
<option>php&mysql
</select></span>
Prompt to limit the number of characters entered
<script language= "JavaScript" >
<!--
function Symerror ()
{
return true;
}
Window.onerror = Symerror;
function Strlength (str) {
var l=str.length;
var n=l
for (Var i=0;i<l;i++)
{
if (Str.charcodeat (i) <0| | Str.charcodeat (i) >255) n++
}
return n
}
function Changebyte (value,length) {
var l=strlength (value)
if (l<=length) {
if (document.all!=null) document.all ("byte"). Innertext= "can also enter" + (LENGTH-L) + "byte"
}
Else
{
document.all ("byte"). Innertext= "Enter bytes out of range"
}
return True
}
function Changebyte1 (value,length) {
var l=strlength (value)
if (l<=length) {
if (document.all!=null) document.all ("Byte1"). innertext= "also can enter" + (LENGTH-L) + "byte"
}
Else
{
document.all ("Byte1"). innertext= "Enter bytes out of range"
}
return True
}
function Changebyte2 (value,length) {
var l=strlength (value)
if (l<=length) {
if (document.all!=null) document.all ("Byte2"). innertext= "also can enter" + (LENGTH-L) + "byte"
}
Else
{
document.all ("Byte2"). innertext= "Enter bytes out of range"
}
return True
}
</script>
<form method= "POST" Name=test onsubmit= "return Checkdata ()" action= "" >
<textarea onkeydown= "return changebyte1 (document.test.icqcontent.value,198)" onkeyup= "Return Changebyte1 ( document.test.icqcontent.value,198) "Name=icqcontent cols=40 rows=" 3 "></TEXTAREA>
<span id=byte1><script language=javascript>changebyte1 (document.test.icqcontent.value,198); </ Script></span>
</form>
Determine the limit of the number of words to fill
<script language=javascript>
function Gbcount (message,total,used,remain)
{
var Max;
max = Total.value;
if (Message.value.length > Max) {
Message.value = message.value.substring (0,max);
Used.value = max;
Remain.value = 0;
Alert (' message can not exceed the specified number of words! ');
}
else{
Used.value = Message.value.length;
Remain.value = Max-used.value;
}
}
</script>
<form name= ' MyForm ' >
<textarea name= ' guestcontent ' cols= ' rows= ' 6 ' Onkeydown=gbcount (This.form.guestcontent,this.form.total, This.form.used,this.form.remain); Onkeyup=gbcount (This.form.guestcontent,this.form.total,this.form.used,this.form.remain);></textarea>
Maximum words: <input disabled maxlength=4 name=total size=3 value=20>
Words used: <input disabled maxlength=4 name=used size=3 value=0>
Remaining words: <input disabled maxlength=4 name=remain size=3>
</form>
Register Read Time Wait button
<form action= "Http://www.jb51.net"; Method= "POST" name= "Agree" >
Welcome to register Soot Blog:
A number of articles ...
<input type= "Submit" value= "please look carefully < terms of service and declaration > ()" Name= "Agreeb" >
</form>
<script language=javascript>
<!--
var secs = 15;
Document.agree.agreeb.disabled=true;
for (i=1;i<=secs;i++) {
Window.settimeout ("Update (" + i + ")", I * 1000);
}
function Update (num) {
if (num = = secs) {
Document.agree.agreeb.value = "I agree";
Document.agree.agreeb.disabled=false;
}
else {
Printnr = Secs-num;
Document.agree.agreeb.value = "Please look carefully < terms and conditions of service > (" + Printnr + ")";
}
}
-->
</SCRIPT>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.