Haloo, i have a problem here
Its my Validation Script
foreach ($product_options as $product_option) {
if ($product_option['required'] && empty($option[$product_option['product_option_id']])) {
$json['error']['product']['option'][$product_option['product_option_id']]
= sprintf($this->language->get('error_required'), $product_option['name']);
}
}
And its my Div Id
<div id="option-<?php echo $option['product_option_id']; ?>" class="option">
For now, that script just show up " fieldname is Required!"
i want it focus on the empty required field and show the "fieldname is Required!" text , Thank you
When you detect an error, output Javascript that sets focus on the invalid field.
foreach ($product_options as $product_option) {
if ($product_option['required'] && empty($option[$product_option['product_option_id']])) {
$json['error']['product']['option'][$product_option['product_option_id']]
= sprintf($this->language->get('error_required'), $product_option['name']);
?>
<script>
$(function () {
$("#option-<?php echo $product_option['product_option_id'] ?> input").focus();
});
</script>
<?php
}
}
Related
i have a problem with checkbox . i want to check all when the first checkbox is checked. this is my code
<tr>
<td><label for="">Pilih Pendidikan</label></td>
<td style="text-align:left;">
<input type="checkbox" id="pilih_semua_pdk">Pilih Semua
<?php foreach ($query2 as $row2) {?>
<input class="form-control required check_pdk" type="checkbox" name="pendidikan[]" value="<?php echo $row2[id_pendidikan]; ?>"
<?php
$pendidikan = $_POST[pendidikan];
if ($pendidikan !=NULL) {
foreach($pendidikan as $pendidikan){
if ($pendidikan == $row2[id_pendidikan]) {
echo "checked";
}
}
}
?>
><?php echo $row2[nama_pendidikan]; ?>
<?php } ?>
</td>
</tr>
i try this code but doesnt work
<script>
$("#pilih_semua_pdk").click(function () {
$(".check_pdk").prop('checked', $(this).prop('checked'));
</script>
Try this, you need to bind an click event on first checkbox. On click of the first checkbox check if that is checked!. If yes then find all checkbox to get going.
$('#pilih_semua_pdk').on('click', function(){
if( $(this).is(':checked'))
{
//find parent td and its all checkboxes excluding first
$(this).parent().find('input[type=checkbox]').not('#pilih_semua_pdk').each(function(){
$(this).prop('checked', true);
});
}
});
jQuery makes this a piece of cake.
$(document).ready(function(){
// DOM has been loaded, attach click event for first checkbox
$('#pilih_semua_pdk').on('click', function(){
// verify if it is checked
if($(this).is(':checked'))
{
// check/tick the remaining checkboxes of the same td
$(this).siblings('.check_pdk').prop('checked', 'checked');
}
else
{
// do something when the first checkbox is unchecked
}
});
});
Please someone help me..i want to delete multiple items with check box selection in code igniter..
what i did: My view page looks like this
<script type="text/javascript" src="<?php echo base_url(); ?>/js/jquery_1_8_1_min.js"></script>
<script language="javascript">
$(function(){
$("#selectall").click(function () {
$('.case').attr('checked', this.checked);
});
$(".case").click(function(){
if($(".case").length == $(".case:checked").length) {
$("#selectall").attr("checked", "checked");
} else {
$("#selectall").removeAttr("checked");
}
});
});
</script>
<?php
foreach($query as $row)
{
?>
<tr><td><input name="checkbox[]" class="case" type="checkbox" value="<?php print $row->reg_id; ?>"></td></tr>
<?php
}
?>
My controller code:
function del($reg_id) //delete content
{
$this->load->helper(array('form','url'));
$this->load->model('registration');
$query=$this->registration->delete($reg_id);
$data['query']=$this->registration->cr_getall();
$this->load->view('vw_register',$data);
}
Here my model:
public function del($reg_id)
{
$this->load->database();
$del=$this->db->delete('tbl_contctform',array('reg_id'=>$reg_id));
if($del)
{
return $del;
}
else
{
return false;
}
}
I know i done some mistakes.but i dont knw how to clear that.
is it possible to use ajax .?Please help me.
Try this,
$(".case").on('click',function(){
var chk=$('.case:checked').length ? true : false;// if length is > 0 then return true
$('#selectall').prop('checked',chk);// if chk true then check the selectAll checkbox
});
Take a look on fiddle
You need to create a form submit and call the function of controller on form submit
# Your Controller Function
function del($reg_id) //delete content
{
$this->load->helper(array('form','url'));
$this->load->model('registration');
$checkbox=$this->input->post('checkbox');# Using Form POST method you can use whatever you want like GET
$reg_id=$this->input->post('reg_id');# Using Form POST method
$regId_array=array();
foreach($checkbox as $key=>$checked)
{
if($checked!==FALSE)
$regId_array[]=$reg_id[$key];
}
if(!empty($regId_array))# array of checked reg_id to delete
{
$query=$this->registration->del($checkbox,$id);# use del here not delete as your model says
}
else{
die('No checkbox selected!!!');
}
$data['query']=$this->registration->cr_getall();
$this->load->view('vw_register',$data);
}
# Your Model Function
public function del($reg_id)
{
$this->load->database();
$this->db->where_in('reg_id', $reg_id);# delete all reg_id in $reg_id array variable
$this->db->delete('tbl_contctform');
if($del)
{
return $del;
}
else
{
return false;
}
}
And your View should be like,
<?php
foreach($query as $row)
{
?>
<tr><td>
<input name="checkbox[]" class="case" type="checkbox" />
<input name="reg_id[]" type="hidden" value="<?php print $row->reg_id; ?>">
</td></tr>
<?php
}
?>
I changed my View,Controller,Model like this..now it working properly
View:
<form name="forms" action="delete_checkbox/" method="post">
foreach($query as $row)
{?>
<tr>
<td><input type="checkbox" name="forms[]" id="forms[]"
value="<?php print $row->reg_id; ?>"/>
</tr?
<?php } ?>
Controller:
function delete_checkbox() {
$dat = $this->input->post('forms');
for ($i = 0; $i < sizeof($dat); $i++) {
print_r($dat[$i]);
$this->load->model('registration');
$this->registration->delete_check($dat[$i]);
}
redirect('viewreg/showall', 'refresh');
}
It works!!
I have a simple jquery modal box on my site. I'm new at jquery so I'm not sure how to keep the box open if an error is posed on the form that is being submitted. If submitted correctly redirect.
As of now when there is an error it reloads the page and have to press pop up again to view error.
Thanks in advance.
if(isset($_POST['submit'])) {
$email = $_POST['email'];
if(empty($_POST['name']) || empty($_POST['email'])) {
$error = "Please enter the info in the fields that are marked <br /> with *";
}elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$error_email = "Please enter a valid email address";
}else{
$success = true;
$success = "Thank You";
mysql_query("INSERT INTO watch_list
(name, email) VALUES('".$_POST['name']."', '".$_POST['email']."')")
or die(mysql_error());
header( 'Location: /watch.php' );
}
}
<div class="play_wrapper">
<div class="play">
<img src="/styles/images/lx_play.png"/>
<div id="toPopup">
<div id="popup_content">
<div class="vid_form_text">
Please enter your name and email to watch the film. <span class="green">Thank you.</span>
</div>
<?php if(isset($success)) { ?>
<div class="success_watch">Thank You!</div>
<?php } ?>
<?php if(isset($error)) { ?>
<div class="error_watch">
<?php echo $error; ?>
</div>
<?php } ?>
<?php if(isset($error_email)) { ?>
<div class="error_watch">
<?php echo $error_email; ?>
</div>
<?php } ?>
<form method="post" action="#">
<div class="form_text_sign_up_required">
All fields marked with an asterisk * are required
</div>
<div class="form_text_sign_up">
Name*
</div>
<input type="text" name="name" value="<?php if(isset($_POST['name'])) {echo $_POST['name'];} ?>" /> <br /><br />
<div class="form_text_sign_up">
Email*
</div>
<input type="text" name="email" value="<?php if(isset($_POST['email'])) { echo $_POST['email'];} ?>" /><br /><br />
<input type='submit' name='submit' value='submit' class='post'/>
</form>
</div> <!--your content end-->
</div> <!--toPopup end-->
<div class="loader"></div>
<div id="backgroundPopup"></div>
</div>
</div>
<script>
jQuery(function($) {
$("a.topopup").click(function() {
loading(); // loading
setTimeout(function(){ // then show popup, deley in .5 second
loadPopup(); // function show popup
}, 500); // .5 second
return false;
});
/* event for close the popup */
$("div.close").hover(
function() {
$('span.ecs_tooltip').show();
},
function () {
$('span.ecs_tooltip').hide();
}
);
$("div.close").click(function() {
disablePopup(); // function close pop up
});
$(this).keyup(function(event) {
if (event.which == 27) { // 27 is 'Ecs' in the keyboard
disablePopup(); // function close pop up
}
});
$("div#backgroundPopup").click(function() {
disablePopup(); // function close pop up
});
$('a.livebox').click(function() {
alert('Hello World!');
return false;
});
/************** start: functions. **************/
function loading() {
$("div.loader").show();
}
function closeloading() {
$("div.loader").fadeOut('normal');
}
var popupStatus = 0; // set value
function loadPopup() {
if(popupStatus == 0) { // if value is 0, show popup
closeloading(); // fadeout loading
$("#toPopup").fadeIn(0500); // fadein popup div
$("#backgroundPopup").css("opacity", "0.7"); // css opacity, supports IE7, IE8
$("#backgroundPopup").fadeIn(0001);
popupStatus = 1; // and set value to 1
}
}
function disablePopup() {
if(popupStatus == 1) { // if value is 1, close popup
$("#toPopup").fadeOut("normal");
$("#backgroundPopup").fadeOut("normal");
popupStatus = 0; // and set value to 0
}
}
/************** end: functions. **************/
}); // jQuery End
</script>
You'll want to handle this using AJAX. If you send the response back in JSON format, it makes it super easy to parse out if it was successful or not.
$('form').on('submit', function(e) {
var form = $('form')[0];
var data = new FormData(form);
// http://api.jquery.com/jQuery.ajax/
$.ajax({
url : 'Your URL',
data : data,
type: 'POST',
errror : function(xhr, status, err) {console.log(xhr, status, err);}, // This only gets thrown if form submits unsucessfully
success: function(response, status) {
// This assumes the response you're sending back from PHP is JSON
var data = JSON.parse(response);
if (data.error) {
// Handle form being unsuccessful
} else {
// Handle success
}
}
});
// This is to prevent the form from actually submitting.
e.preventDefault();
return false;
});
I'm working on a message system where users submit one response to another user. The receiver then views all of his messages in a while loop. I created a delete button that will delete the whichever message the delete button is linked to. I have two problems. First, the delete button does not work, and second, when it was working (it no longer is) the while loop was linking all the delete buttons to the first message and not individually to each message the while loop produced. Also, I'm aware that mysql is deprecated. Will be making the transition over soon.
Here is the first code:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript" >
function load(thefile, thediv) {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject ('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById(thediv).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET', thefile + key, true);
xmlhttp.send();
}
</script>
<?php
while($ergo_data = mysql_fetch_assoc($ergo_query_result)) {
echo 'Message: ' . $ergo_data['ergo'] . '<br>';
echo 'From: ' . username_from_user_id($ergo_data['user_id_seeker']) . '<br>';
echo 'Time submitted: ' . $ergo_data['ergo_time_submitted'] . '<br><br><br><br>';
echo $ergo_data['primary_key'];
?>
<div class="changes">
<input type="button" value="delete" class="<?php echo $ergo_data['primary_key']; ?>"
name="<?php echo $ergo_data['user_id_seeker']; ?>"
onclick="load('ajax_ergo_list.php?key=',
'delete');">
</div>
<script type="text/javascript" >
$(document).ready(function(){
var key = $(".changes :input").attr("class");
alert(key);
});
</script>
<br>
<br>
<br>
<?php
}
?>
<div id="delete"></div>
Here is the second file containing what I want to happen when the button is pressed.
if (isset($_GET['key'])) {
$key = sanitize($_GET['key']);
}
if (!empty($key)) {
$query = "DELETE FROM `ergo` WHERE `primary_key` = '$key'";
$query_run = mysql_query($query);
echo 'Deleted!';
}
?>
Ok, first off, this is all sorts of crazy code you got going on here...
<script type="text/javascript" >
$(document).ready(function(){
var key = $(".changes :input").attr("class");
alert(key);
});
</script>
You have your script inside a while loop. That will alert as many times as the loop is. And that is really all the function does. It's not setting a global variable or anything.
In regards to jQuery, use it:
function load(thefile, thediv) {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject ('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById(thediv).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET', thefile + key, true);
xmlhttp.send();
}
Condense that to this:
function load(thefile, thediv) {
$.get(thefile+key,function(responseText){
$('#'+thediv).html(responseText);
});
}
In regards to your question about the delete function:
<div class="changes">
<input type="button" value="delete" class="<?php echo $ergo_data['primary_key']; ?>"
name="<?php echo $ergo_data['user_id_seeker']; ?>"
onclick="load('ajax_ergo_list.php?key=',
'delete');">
</div>
Your onclick is the javascript that is firing. You have the first variable set to the link and the second to the action I am guessing? In your function code, the second variable is supposed to be the div where the info is displayed. The key is no where to be found. Try doing this instead:
<div class="changes">
<input type="button" value="delete" class="<?php echo $ergo_data['primary_key']; ?>"
name="<?php echo $ergo_data['user_id_seeker']; ?>"
onclick="load('ajax_ergo_list.php?key=<?php echo $ergo_data['primary_key'];?>',
'delete');">
</div>
And your load function to this:
function load(thefile, thediv) {
$.get(thefile,function(responseText){
$('#'+thediv).html(responseText);
});
}
Good luck!
I'm posting on this forum because I don't manage to received my information that I posted by my submit form into my showidz.php page. I don't know how to catch my $_POST["numversion"] which generated my ajax script in my docversion.php.
to sum up, I have a form page docversion.php where I enter the document name and I catch on the same page the "linked" versions which are possible for this document entered by using an ajax script. This works fine.
My problem is when I click on the submit to throw information from docversion.php to showidz.php I cannot catch the numversion.
Here's my source code :
docversion.php
<script type='text/javascript'>
function getXhr(){
var xhr = null;
if(window.XMLHttpRequest) // Firefox
xhr = new XMLHttpRequest();
else
if(window.ActiveXObject) { // Internet Explorer
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else { // XMLHttpRequest non supporté par le navigateur
alert("Browser not compatible with XMLHTTPRequest...");
xhr = false;
}
return xhr;
}
/**
* catch on click
*/
function go(){
var xhr = getXhr();
// do when we have the answer
xhr.onreadystatechange = function(){
// do if the server answer is OK
if(xhr.readyState == 4 && xhr.status == 200){
leselect = xhr.responseText;
// use innerHTML
document.getElementById('numeroversion').innerHTML = leselect;
}
}
// post to rep_PhpAjax.php to have version
xhr.open("POST","rep_PhpAjax.php",true);
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
sel = document.getElementById('course');
iddocument = sel.value;
xhr.send("idDoc="+iddocument);
}
</script>
<form name="test1" method="post" action="showidz.php" >
Nom du document <label>:</label><br>
<input type="text" name="course" id="course" size="40" onclick='go()'/><br/>
<label>Version</label>
<div id='numeroversion' style='display:inline'>
<select name='numeroversion'>
<option value='-1'>Choose a version</option>
</select>
</div>
<input type="submit" name="OK" value="OK">
</form>
rep_PhpAjax.php
<?php
echo "<select name='numeroversion'>";
if(isset($_POST["idDoc"])){
$res = mysql_query("SELECT `NumeroVersion`
FROM `version`, document
WHERE document.idversion = version.idversion
and document.NomDocument ='".$_POST["idDoc"]."'");
while($row = mysql_fetch_assoc($res)){
echo "<option value='".$row["idversion"]."'>".$row["NumeroVersion"]."</option>";
}
}
echo "</select>";
?>
showidz.php : The page with the problem where i cannot have the numeroversion which has been posted for docversion.php:
<?php
$docname = $_POST["course"];
$idversion = $_POST["numeroversion"];
echo "$docname</br>";
echo $idversion;
?>
Hope that someone could help me on my problem.
there seems to be nothing wrong with the form data that gets sent to showidz.php
but a problem might be the fact that you are calling that ajax on click. maybe you should chnage
onclick="go();"
to
onkeyup="go();"
in docversion.php at line 54 so that the ajax is called every time you type a letter
I rewrited what you want to do using jQuery. You can see it in action here.
Folder Structure:
site -+- displayDocument.php
|- ajaxGetVersions.php
|- ajaxGetVDocument.php
|- queries.php
displayDocument.php:
<?php
require_once 'queries.php';
$documents = getDocuments();
?>
<form id="myform" method="post" action="" >
<label for="documents">Choose a document</label>
<select id="documents" name='documents[]'>
<option value='0'>Choose a document</option>
<?php foreach ($documents as $document) : ?>
<option value='<?php echo $document ?>'><?php echo $document ?></option>
<?php endforeach; ?>
</select>
<br/>
<label for="versions">Version </label><span id="refreshVersions"></span>
<select id="versions" name='versions[]'>
</select>
<br/>
<input type="submit" name="OK" value="OK">
</form>
<div id="refreshDocument"></div>
<div id="document"></div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$("#documents").change(function() {
$("#refreshVersions").text("refreshing...");
$.post("ajaxGetVersions.php", { documentId: $(this).val() },
function(data) {
$("#versions").html(data);
$("#refreshVersions").text("");
});
});
$("#myform").submit(function(e) {
$("#refreshDocument").text("refreshing...");
$.post("ajaxGetDocument.php", { documentId: $("#documents").val(), version: $("#versions").val() },
function(data) {
$("#document").html(data);
$("#refreshDocument").text("");
});
e.preventDefault();
});
</script>
ajaxGetVersions:
<?php
require_once 'queries.php';
if (!isset($_POST['documentId'])) {
die('missing post parameter: documentId');
}
$versions = getVersionsOfDocument($_POST['documentId']);
?>
<?php foreach ($versions as $version): ?>
<option value='<?php echo $version ?>'><?php echo $version ?></option>
<?php endforeach; ?>
ajaxGetDocument:
if (!isset($_POST['documentId']) || !isset($_POST['version'])) {
die('missing post parameter: documentId or version');
}
$doc = getDocument($_POST['documentId'], $_POST['version']);
?>
<h1><?php echo $doc["documentId"] ?></h1>
<h2><?php echo $doc["version"] ?></h2>
<h3><?php echo $doc["author"] ?></h3>
<p>
<?php echo $doc["content"] ?>
</p>
queries.php:
<?php
// little database replace
$documents = array("Book1" => array("beta", "1.0", "1.1", "2.0"), "Book2" => array("1.0", "1.1"), "Book3" => array("beta"));
function getVersionsOfDocument($documentId) {
// replace with database fetch
global $documents;
return $documents[$documentId];
}
function getDocuments() {
// replace with database fetch
global $documents;
return array_keys($documents);
}
// get a document by id and version
function getDocument($documentId, $version) {
//implement your own
return array("documentId" => $documentId,
"version" => $version,
"author" => "...",
"content" => "bla bla");
}