Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am getting problem while validating multiple text box of same class.
can you please tell me a solution.my html code is as follows.
<input type="text" placeholder="Country Code" class="phone" /><input type="text" placeholder="phone number" class="phone" />

I just want to validate.
Posted
Comments
TrushnaK 30-Aug-13 8:55am    
you not given ids to both textboxes then how could you identify perticular textbox.

what you want to validate?
project virus 30-Aug-13 9:01am    
We can not use id for multiple textbox.one id for one textbox.that's why I used class.To identify particular textbox i used document.getElementByClassname("phone");

1 solution

use id in your text boxes and select text box by their respective id instead of class.

HTML
<input id="t1" type="text" placeholder="Country Code" class="phone" />
<input id="t2" type="text" placeholder="phone number" class="phone" />


JavaScript
$(document).ready(function(){
$('#t1').......; //selector as id
$('#t2').......; // select as id
});
 
Share this answer
 
Comments
project virus 30-Aug-13 9:05am    
yes but i want to display same msg for same span and also want to insert into database of same column via php
[no name] 30-Aug-13 9:07am    
give me your whole form which you want to validate and insert via php.
project virus 30-Aug-13 9:12am    
<form action="mail.php" class="contactForm" name="cform" method="post">
<p>Enquire Anything.We’ll get back to you shortly.</p>
<div class="input_boxes">
<p><label for="name">Name</label><span class="name-missing">Please enter your name</span><br />
<input id="name" type="text" value="" name="name" /></p>
<p><label for="phone">Phone</label><span class="phone-missing">Please enter your phone number with country code</span><br />
<input id="phone" class="phone" type="text" value="" name="phone[]" style="width:50px;" placeholder="Code" maxlength="5" /> <input id="phone" class="phone" type="text" value="" name="phone[]" maxlength="15" /></p>
<p><label for="e-mail">E-mail</label><span class="email-missing">Please enter a valid e-mail</span><br />
<input id="e-mail" type="text" value="" name="email" /></p>
<p><label for="message">Message</label><span class="message-missing">Say something!</span><br />
<textarea id="message" rows="6" cols="6" name="message"></textarea></p>
</div>
<input class="submit" type="submit" name="submit" value="Submit Form" önfocus="this.blur()" />
</form>
[no name] 30-Aug-13 9:16am    
id "phone" must be unique means "phone1" and "phone2"
and please tell me what u want right now hv write any jquery yet for validation ?
project virus 30-Aug-13 9:20am    
<span class="phone-missing">Please enter your phone number with country code</span> should be display when both fields are null and it should be numeric

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900