Click here to Skip to main content
15,881,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made the coding of javascript validation for editor(i am using ckeditor).It is not working properly.i.e when i am going to submit the form at first the alert box is coming as the editor is empty but when i am adding some content and going to validate it ,still the alert box is coming.After it everything goes fine.But i want that the alert box will come once ,when the editor field is empty.So please suggest me.Below is my coding.Thank you.
HTML
<!---------------- java script validation starts here--------------------------->
<script type="text/JavaScript">


function validate()
{ 
	var partnername = document.getElementById("partnername").value;
		var descrip = document.getElementById("description").value;
	var img = document.getElementById("image").value;
		if(partnername == "")
	{
		alert("Please Enter partner name");
		document.getElementById("partnername").focus();
		document.getElementById("partnername").style.borderColor="#fd00d6";
		return false;
	}

	
		if(descrip  == "")
	{
		alert("Please Enter partner description");
		document.getElementById("description").focus();
		document.getElementById("description").style.borderColor="#fd00d6";
		return false;
	}
	
	
	
		if(img == "")
	{
		alert("Please Enter partner image");
		document.getElementById("image").focus();
		document.getElementById("image").style.borderColor="#fd00d6";
		return false;
	}
	
	
	
}
</script>
<script src="ckeditor/ckeditor.js"></script>

<aside class="right-side">
  <section class="removed-header">
    <h1> Manage Partners </h1>
    <ul class="breadcrumb" style="margin-removed10px;">
      <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li>
      <li><a href="manage-partners.php">Partner</a></li>
      <a class="btn btn-primary" href="manage-partners.php?post=add">Add Partners</a>
    </ul>
  </section>
  
  <div class="alert alert-success alert-dismissable" style="width:97%;"> <i class="fa fa-check"></i> <b></b> </div>
  <?php }else if($error!= '') { ???>
  <div class="alert alert-danger alert-dismissable" style="width:97%;"> <i class="fa fa-ban"></i> <b></b> &nbsp;&nbsp; </div>
  <?php } ???>
  <div class="col-md-6">
    <?php if($_REQUEST['post'])<br mode="hold" /??>                     {
                     ?>
    <div class="box box-primary">
      <div class="box-header">
        <h3 class="box-title">Add Partner</h3>
      </div>
      <form role="form" action="" method="post" enctype="multipart/form-data" >
        <div class="box-body">
          <div class="form-group">
            <label for="exampleInputEmail1">Partner Name</label>
            <input type="text" class="password" id="partnername" placeholder="Enter Partner Name" name="partnername" value="<?php echo $_REQUEST['partnername'];???>"  >
          </div>
          <div class="form-group">
            <label for="exampleInputEmail1">Partner Description</label>
            <textarea id="description" name="description"   rows="10" cols="80" class="ckeditor" ><?php echo $_REQUEST['description'];???> </textarea>
          </div>
          <div class="form-group">
            <label for="exampleInputFile">Partner Image</label>
            <input type="file" id="image" name="image" value="<?php echo $_REQUEST['image'];???>">
            <p class="text-red">(please insert 100*100 size and gif,jpg,jpeg,png format only)</p>
          </div>
        </div>
        <div class="box-footer">
          <button type="submit" class="btn btn-primary" name="add_partner">Submit</button>
        </div>
      </form>
    </div>
    <?php } ???>
  </div>
  
   
</aside>
Posted
Updated 18-Dec-14 23:58pm
v5

1 solution

Hi...
Use like this, may its helpfull to you...

C#
function validate()
{   
  var partnername = document.forms["form_id"]["partnername"].value;
  var descrip = document.forms["form_id"]["description"].value;
  var img = document.forms["form_id"]["image"].value;
  if(partnername == "" || partnername == null )
  {
    alert("Please Enter partner name");
    document.getElementById("partnername").focus();
    document.getElementById("partnername").style.borderColor="#fd00d6";
    return false;
  }
   and so on...
}

Thank you.
 
Share this answer
 
Comments
Sradhanjali Behera 19-Dec-14 5:53am    
its not working ): @Murali0195.Help me plz
[no name] 19-Dec-14 6:48am    
See this link:
http://www.w3schools.com/js/tryit.asp?filename=tryjs_form_validation
Sradhanjali Behera 19-Dec-14 10:30am    
ok i am checking.I will give my reply soon @Murali0195
Sradhanjali Behera 19-Dec-14 10:37am    
you are right.but in tha case of text editor it doesnot work properly.same problem is coming.It properly works for text field.but not for editor.After inserting data to editor ,when i am going to click upon submit buttoon.alert message is coming.which is the issue.so ......thank you @Murali0195
[no name] 22-Dec-14 4:04am    
Welcome

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