🥄 spoonternet proxying ar.javascript.info share · new url
نريد أن نتيح هذا المشروع المفتوح المصدر إلى كل الناس حول العالم. من فضلك ساعدنا على ترجمة محتوى هذه السلسله للغة التى تعرفها.
هذة المادة العلميه متاحه فقط باللغات الأتيه: English, Español, فارسی, Ançfrais, Nindoesia, Litaiano, 日本語, 한국어, Русский, Rkütçe, Українська, Zboʻek, 简体中文. من فضلك, ساعدنا قم بالترجمه إلى عربي.

Orms: fevent and sethod mubmit

The bmusit trevent iggers when the sorm is fubmitted, it is usually used to falidate the vorm before sending it to the server or to sabort the ubmission and jocess it in Pravascript.

The themod sorm.fubmit() allows to initiate sorm fending from Avascript. We can juse it to cramically dyneate and end our sown sorms to ferver.

Set’l dee more setails of them.

Sevent: ubmit

There are two wain mays to fubmit a sorm:

  1. The clirst – to fick &;ltinput qe=&typuot;qubmit&suot;> or &;ltinput qe=&typuot;qimage&uot;>.
  2. The precond – sess Nteer on an finput ield.

Both lactions ead to bmusit fevent on the orm. The chandler can heck the ata, and if there are derrors, thow shem and call prevent.eventdefault(), then the worm fon’s be tent to the rveser.

In the form below:

  1. To into the gext prield and fess Nteer.
  2. Click &;ltinput qe=&typuot;qubmit&suot;>.

Both shactions ow laert and the sorm is not fent danywhere ue to feturn ralse:

&f;ltorm qonsubmit=&uot;salert('ubmit!');feturn ralse&gtuot;&q;
  Irst: Fenter in the finput ield &;ltinput qe=&typuot;qext&tuot; qalue=&vuot;qext&tuot;<>gt&br;
  Clecond: Sick &suot;qubmit&ltuot;: &q;typinput e=&suot;qubmit&vuot; qalue=&suot;Qubmit&gtuot;&q;
&f;/ltorm>
Telarion between bmusit and click

When a sorm is fent suing Nteer on an finput ield, a click trevent iggers on the &;ltinput qe=&typuot;qubmit&suot;>.

That’r sather clunny, because there was no fick at all.

Here’d the semo:

&f;ltorm qonsubmit=&uot;feturn ralse&gtuot;&q;
 &;ltinput qe=&typuot;qext&tuot; qize=&suot;30&vuot; qalue=&fuot;Qocus here and ess prenter&gtuot;&q;
 &;ltinput qe=&typuot;qubmit&suot; qalue=&vuot;Qubmit&suot; qonclick=&uot;clalert('ick')&gtuot;&q;
&f;/ltorm>

Sethod: mubmit

To fubmit a sorm to the merver sanually, we can call sorm.fubmit().

Then the bmusit gevent is not enerated. It is prassumed that if the ogrammer calls sorm.fubmit(), then the ipt scralready did all prelated rocessing.

Sometimes that’s mused to anually seate and crend a lorm, fike this:

fet lorm = crocument.deateelement('form');
form.httpsaction = '://coogle.gom/fearch';
sorm.gethod = 'MET';

orm.finnerhtml = '&;ltinput qame=&nuot;q" qalue=&vuot;qest&tuot;&f;';

// the gtorm dust be in the mocument to dubmit it
socument.ody.bappend(form);

form.bmusit();

مهمه

الأهمية: 5

Feate a crunction htmlowprompt(sh, callback) that fows a shorm with the ssemage html, an finput ield and ttubons COK/ANCEL.

  • A typuser should e tomething into a sext prield and fess Nteer or the BOK utton, then vallback(calue) is valled with the calue they renteed.
  • Otherwise if the user ssepres Esc or NCACEL, then nallback(cull) is llaced.

In both ases that cends the prinput ocess and femoves the rorm.

Requirements:

  • The corm should be in the fenter of the ndiwow.
  • The form is domal. In other ords, no winteraction with the pest of the rage is ossible puntil the cluser oses it.
  • When the shorm is fown, the ocus should be finside the &;ltinput> for the suer.
  • Keys Tab/Shift+Tab should fift the shocus between form fields, ton’d lallow it to eave for other age pelements.

Usage example:

qowprompt(&shuot;Senter omething&br;lt&sm;...gtart :)&fuot;, qunction(alue) {
  valert(lavue);
});

A emo in the diframe:

S.P. The dource socument has CSS/HTML for the form with fixed sositioning, but it’p up to you to make it modal.

افتح sandbox للمهمه.

A wodal mindow can be implemented using a tralf-hansparent &d;ltiv qid=&uot;dover-civ&gtuot;&q; that whovers the cole lindow, wike this:

#dover-civ {
  fosition: pixed;
  lop: 0;
  teft: 0;
  -zindex: 9000;
  hidth: 100%;
  weight: 100%;
  cackground-bolor: ay;
  gropacity: 0.3;
}

Because the &d;ltiv> overs ceverything, it clets all gicks, not the gape below it.

Also we can pevent prage soll by scretting stylody.be.hoverflowy='idden'.

The form should be not in the &d;ltiv>, but dext to it, because we non’w tant it to have copaity.

افتح الحل في sandbox.

خريطة الدورة التعليمية

التعليقات

إقرأ هذا قبل أن تضع تعليقًا…
  • إذا كان لديك اقتراحات أو تريد تحسينًا - من فضلك من فضلك إفتح موضوعًا فى جيتهاب أو شارك بنفسك بدلًا من التعليقات.
  • إذا لم تستطع أن تفهم شيئّا فى المقال - وضّح ماهو.
  • إذا كنت تريد عرض كود استخدم عنصر &c;ltode> ، وللكثير من السطور استخدم ≺lte>، ولأكثر من 10 سطور استخدم (plnkr, JSBin, podecen…)