JavaScript creates new tags, judges keyboard input, and determines focus (sample code) _javascript Tips

Source: Internet
Author: User

As shown below:

Copy Code code as follows:

function Saomiao (event,n)
{
var code=0;
code=event.keycode;//listening for keyboard input events
if (code== ' 13 ')//If the keyboard enters the ENTER key
{
if (n>0)//Start judging parameters
{
if (document.getElementById (' Logisticsno '). value== ')
{
Alert (' Please scan input waybill number! ');
var R=document.getelementbyid (' Logisticsno ');
R.focus ();
return false;
}
else if (document.activeelement.name!= ' Deliver_money ')//document.activeelement.name the element name where the focus is
{
var R=document.getelementbyid (' Deliver_money ');
R.focus ();
}
else//if all the conditions are met
{
var R=document.getelementbyid (' Logisticsno ');
R.focus ();
var f=document.createelement (' form ');/Start new Form
f.action= '/modules/logistics/start.php ';
Document.body.appendChild (f);//Add to Body

var e=document.createelement (' input ');//New FORM element
E.type= ' hidden ';
E.name= ' act ';
e.id= ' act ';
E.value= ' Logisticsno ';
F.appendchild (e);//Add to form

var data_id=0;
var g=document.getelementsbyname ("orderdataid_no[]");
var h=0;
for (Var h=0;h<g.length;h++)
{
Data_id=g[h].value;
}

var order_no=0;
var gg=document.getelementsbyname ("order_no[]");
var hh=0;
for (Var hh=0;hh<gg.length;hh++)
{
Order_no=gg[hh].value;
}

var k=document.createelement (' input ');
K.type= ' hidden ';
K.name= ' Order_no ';
K.id= ' Order_no ';
K.value=order_no;
F.appendchild (k);

F.submit ()//form submission
}
}
}
}
<body onkeypress= "Javascript:saomiao (event,555);" >//starts monitoring keyboard input

Related Article

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.