Sélectionner un champ par son nom avec jQuery

Avril 2013

Lorsqu'on utilise jQuery pour vérifier un formulaire en Javascript, il est possible de sélectionner les différents champs en se basant sur l'attribut name, cela évite ainsi de devoir attribuer à chaque champ un id juste pour ça.

Pour cela, il suffit d'utiliser ce type de sélecteur : $('input[name=recherche]'), voici un petit exemple pratique de validation de formulaire :

<form action="" method="post" id="formulaire">
	<input type="text" name="recherche" value="">
</form>

Cette page peut vous intéresser : défusionner des cellules excel à lire tout de suite !

$('#formulaire').submit(function(e){
	if( $('input[name=recherche]').val() == '' ){
		alert('Le champ est vide');
		e.preventDefault();
		return false;
	}
});

Fini de lire cette page ? allez faire un tour ici : un peu de théorie des couleurs, ça peut vous intéresser.

2 commentaires :
commentaire n°20235 par undilia@gmail.com
undilia@gmail.com lundi 29 mai 2023, 03:49
日本超人気のスーパーコピーブランド激安通販専門店!┏━━━━━2023年人気最高品質━━━━━┓ ◎━ 腕時計、バッグ、財布、アクセサリ ━◎最新入荷!主に販売商品:ロレックスコピー、カルティエコピー、エルメスコピー、ブラダコピー、ルイヴィトンコピー、シャネルコピー、グッチコピー等一流のブランドコピー品。商品の数量は多い、品質はよい、高品質のブランドコピーを超激安な価格で販売しています。信用第一、商品は絶対の自信が御座います!驚きと満足を保証致します。ぜひご来店くださいませ!★ 2023年注文割引開催中,全部の商品割引10% ★ 在庫情報随時更新! ★ 実物写真、付属品を完備する。 ★ 100%品質を保証する。 ★ 送料は無料です(日本全国)!★ 経営方針: 品質を重視、納期も厳守、信用第一!税関の没収する商品は再度無料にして発送します!}}}}}}
https://www.bagssjp.com/product/detail-7592.html
https://www.bagssjp.com/product/detail-10545.html
https://www.bagssjp.com/product/detail-10151.html
https://www.bagssjp.com/product/detail-7511.html
https://www.bagssjp.com/product/detail-7042.html
commentaire n°20258 par undilia@gmail.com
undilia@gmail.com mardi 30 mai 2023, 14:02
ブランドスーパーコピーバッグ、財布、靴、時計各種のブランドは表して、かばん複製品をコピーしますルイヴィトバッグ コピールイヴィトン財布 コピールイヴィトン長財布 コピーブランド偽物、偽物ブランド、ルイヴィトンコピー、 ロレックスコピー、シャネルコピー、グッチコピー、エルメスコピー、 ボッテガ?ヴェネタコピー、 バーバリーコピー }}}}}}
https://www.kyoku66.com/goods-7658.html
facultatif
Facebook Twitter RSS Email
Forum Excel
Venez découvrir le nouveau forum excel question/réponse à la stackoverflow.com !
Forum Excel
hit parade n'en a rien a foutre du W3C Positionnement et Statistiques Gratuites Vincent Paré