0

This is my simple html form code

<form method="post" action=<?php echo base_url()."index.php/controller_bookplot2";?> 
 name="frmbooking" id="frmbooking">
  <div class="marginbtm5">
      <select name="name_title" class="dropdown" id="name_title" required>
        <option value="Mr.">Mr.</option>
        <option value="Miss">Miss</option>
        <option value="Mrs">Mrs</option>
        <option value="Dr.">Dr.</option>
      </select>

      <img src=<?php echo base_url()."images/rightmarked.gif";?> title="mandetory"> 
  </div>
  <div class="marginbtm5">
    <input name="name" type="text" class="input validate_B" id="name" onfocus="if (this.value
      == 'Full Name') {this.value=''}" onblur="if(this.value == '') {
      this.value='Full Name'}" value="Full Name" required>

    <img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory">
  </div>
  <div class="marginbtm5">
    <input name="address" type="text" class="input validate_B" id="add" onfocus="if
      (this.value == 'Address') {this.value=''}" onblur="if(this.value ==
      '') { this.value='Address'}" value="Address" required>

    <img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory">
  </div>
  <div class="marginbtm5">
    <input name="email" type="text" class="input validate_B" id="email" onfocus="if
     (this.value == 'Email') {this.value=''}" onblur="if(this.value ==
     '') { this.value='Email'}" required  value="Email" >

    <img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory"
     style="display:none;">
  </div>
  <div class="marginbtm5">
    <input name="dob" type="text" class="input" value="Birth Date" required id="datepicker" >

    <img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory"> 
  </div>
 <div class="marginbtm5">
    <input name="mobno" type="text" class="input validate_B" maxlength="45" onfocus="if
   (this.value == 'Mobile (10 digit mobile no. eg 9812345678)')
    {this.value=''}" onblur="if(this.value == '') { this.value='Mobile
   (10 digit mobile no. eg 9812345678)'}" value="Mobile (10 digit mobile no. eg
    9812345678)" id="mob_no" pattern="[789][0-9]{9}" required     
        onkeyup="javascript:ValidateText(this)" >
  </div>      
    <input name="btnSubmit" type="image" src=<?php echo base_url()."images/submit.jpg";?> value="Submit" onclick="return validate();">
</form>

There are many other fields in my form. But I just put here 5 fields. When I click on submit, It directly displays html5 required message for mobile no field. It dont validate name,address,email,birthdate field first. So What Am I doing wrong??

2
  • try with closing input tag like this <input /> Commented Dec 1, 2014 at 5:41
  • Tried that ...not working... Commented Dec 1, 2014 at 5:45

2 Answers 2

1

its not working because of you are giving the value attribute remove value attribute and try like this

<form method="post" action=<?php echo base_url()."index.php/controller_bookplot2";?> 
 name="frmbooking" id="frmbooking">
  <div class="marginbtm5">
      <select name="name_title" class="dropdown" id="name_title" required>
        <option value="">--Please select type</option>
        <option value="Mr.">Mr.</option>
        <option value="Miss">Miss</option>
        <option value="Mrs">Mrs</option>
        <option value="Dr.">Dr.</option>
      </select>

      <img src=<?php echo base_url()."images/rightmarked.gif";?> title="mandetory"> 
  </div>
  <div class="marginbtm5">
    <input name="name" type="text" class="input validate_B" id="name" onfocus="if (this.value
      == 'Full Name') {this.value=''}" onblur="if(this.value == '') {
      this.value='Full Name'}" Placeholder="Full Name" required>

    <img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory">
  </div>
  <div class="marginbtm5">
    <input name="address" type="text" class="input validate_B" id="add" onfocus="if
      (this.value == 'Address') {this.value=''}" onblur="if(this.value ==
      '') { this.value='Address'}" Placeholder="Address" required>

    <img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory">
  </div>
  <div class="marginbtm5">
    <input name="email" type="text" class="input validate_B" id="email" onfocus="if
     (this.value == 'Email') {this.value=''}" onblur="if(this.value ==
     '') { this.value='Email'}" required  Placeholder="Email" >

    <img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory"
     style="display:none;">
  </div>
  <div class="marginbtm5">
    <input name="dob" type="text" class="input" Placeholder="Birth Date" required id="datepicker" >

    <img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory"> 
  </div>
 <div class="marginbtm5">
    <input name="mobno" type="text" class="input validate_B" maxlength="45" onfocus="if
   (this.value == 'Mobile (10 digit mobile no. eg 9812345678)')
    {this.value=''}" onblur="if(this.value == '') { this.value='Mobile
   (10 digit mobile no. eg 9812345678)'}" value="Mobile (10 digit mobile no. eg
    9812345678)" id="mob_no" pattern="[789][0-9]{9}" required     
        onkeyup="javascript:ValidateText(this)" >
  </div>      
    <input name="btnSubmit" type="image" src=<?php echo base_url()."images/submit.jpg";?> value="Submit" onclick="return validate();">
</form>

if you add value to input tag then it will not validate that filed because this filed having already value

Sign up to request clarification or add additional context in comments.

1 Comment

Ok...fine but how do I add placeholder to select tag. There are many dropdowns in my form.
0

No need to wirte onfocus="if (this.value == 'Full Name') {this.value=''}" onblur="if(this.value == '') { this.value='Full Name'}" value="Full Name"

this can be achieve by html attribute placeholder='Full Name'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.