Hello i'm new to jquery. I just want to ask a simple question about window.close function The scenario is I created a popup dialog that the user may enter or add another comments using jqueryui which contains a webpage that displays user comments. There are two textfields. One is Category Name and other is Description. Below is the OK submit button and CANCEL button. Before i used the function onclick="window.close();" function i embedded it in my <input type="button" /> but when i tried to run this I can't close the window. What am I going to do? I also tried jquery way but none of it works. Here's my simple code. By the way I am using CodeIgniter framework.
My View (homepage.php)
<?php $data_var = array('id'=>'sa','name'=>'category'); ?>
<?php echo form_open('category_controller/delete_category',$data_var); ?> <!-- use for deleting multiple entries -->
...
<input class="classname1" type="button" value="ADD" name="add_category" />
...
...
<div id="popup" style="display: none;"></div>
...
<!-- Button for ADD ENTRY
...
...
BELOW IS MY JQUERY CODE
<script type="text/javascript">
/*FOR DISPLAYING ADD PAGE*/
$(function(){
$(".hero-unit input[name=add_category]").on('click',function(){
$('#popup').load("<?php echo site_url("category_controller/addCategoryItem/"); ?>").dialog({
title: "Add New Category",
autoOpen: true,
width: 450,
modal:true,
open: function (event, ui) { window.setTimeout(function () {
jQuery(document).unbind('mousedown.dialog-overlay').unbind('mouseup.dialog-overlay'); }, 100);
}
});
});
});
</script>
Here's my CONTROLLER CODE FOR ADD ENTRY
public function addCategoryItem(){
$this->form_validation->set_rules('name','Category Name','required|xss_clean|is_unique[sales_category.salescatname]');
$this->form_validation->set_rules('description','Category Description','required|xss_clean');
if($this->form_validation->run() == FALSE){
$data['title'] = "Add Item";
$data['copyright'] = date('Y');
$this->load->view('User/header/header_user',$data);
$this->load->view('Item/contents/addNewItem');
}else{
$validateInsert = $this->category_model->addCategory();
if(!$validateInsert){
$errNo = $this->db->_error_number();
$errMess = $this->db->_error_message();
$testvar = str_replace("'", "", $errMess);
echo "<script type='text/javascript'>alert('ERROR NO: {$errNo} - {$testvar}');history.back();</script>";
}
redirect('user_controller/homepage','refresh');
}
}
MY MODEL function
public function addCategory(){
$cname = ucwords($this->input->post('name'));
$cdesc = $this->input->post('description');
$insertCategory = array(
'salescatid' => NULL,
'salescatname' => $cname,
'salescatdesc' => $cdesc,
);
$result = $this->db->insert('sales_category',$insertCategory);
if($result){
return TRUE;
}else{
return FALSE;
}
}
MY VIEWS IN ADD ENTRY
<?php $attr = array('class'=>'form-signin'); ?>
<?php echo form_open('category_controller/addCategoryItem',$attr); ?>
<h2 class="form-signin-heading"></h2>
<h5 style="font-weight: normal;">Category Name:</h5>
<input type="text" class="input-block-level" placeholder="Category Name" required="required" name="name" autofocus="autofocus" value="<?php echo set_value('name'); ?>"/>
<label style="color: red;"><?php echo form_error('name'); ?></label>
<h5 style="font-weight: normal;">Desciption</h5>
<input type="text" class="input-block-level" placeholder="Description" required="required" name="description" value="<?php echo set_value('description'); ?>" />
<label style="color: red;"><?php echo form_error('description'); ?></label>
<?php
//VALIDATION FOR RECAPTCHA
//require_once('resources/recaptcha/recaptchalib.php');
//$publickey = "6LcmR-QSAAAAABzJKBdHggBzA2nv9yX5robZuYy9"; // you got this from the signup page
//echo recaptcha_get_html($publickey);
?>
<br />
<div align="right">
<input type="submit" value="OK" class="btn btn-large btn-primary" />
<input type="button" value="CANCEL" class="btn btn-large btn-primary" id="closeForm" onclick="window.close();" />
<!-- NOT FUNCTIONING WHY? -->
</div>
<?php echo form_close(); ?>
That's my code. Hope you can help me.