I'm having a some trouble with a button, I'm using a DIV that has a POST method inside of it, however, this button in question doesn't need the POST method, so:
<div id="lightA" class="white_content" height="300">
<h1>Adivinar...</h1>
<h2>Que personaje escoges?:</h2>
<form type="post">
<input type="text" list="personajes">
<datalist id="personajes" style="display:block">
<?php
session_start();
include "config.php";
if(isset($_SESSION["user_name"]))
{
$select = "SELECT nombre_personaje FROM partida WHERE user_name =".$_SESSION["user_name"]."AND personaje_activo = 'T'";
$query = mysqli_query($con, $select);
$rows = mysqli_num_rows($query);
$cont = 0;
$tableval;
if($rows > 0)
{
while($row = mysqli_fetch_array($query))
{
if($row['personaje_activo'] = "T")
{
=$tableval."<option value=\"".$row['']."\">";
}
}
}
else
{
?>
<?
}
}
echo $tableval;
?>
</datalist>
<button type="submit" action="submit_character.php" name="select" style="display:inline">Elegir!</button>
</form>
<button onclick:"javascript:cerrarPop('lightA')">Cancelar</button>
</div>
Now this is the funny part, <button onclick:"javascript:cerrarPop('lightA')">Cancelar</button> isn't executing anything at all, I was thinking, well just put the button inside the post, however the page refresh itself and executes <body background="imagen.jpg" onload="javascript:mostrarPop('lightP')"> which I don't need, then I was looking how to set a cookie for that pop DIV, but I have a limited knowledge in AJAX.
Here's also my JS script:
<script type="text/javascript">
function mostrarPop(name) {
document.getElementById(name).style.display='block';
document.getElementById('fade').style.display='block';
}
function cerrarPop(name) {
document.getElementById(name).style.display='none';
document.getElementById('fade').style.display='none';
}
</script>
Any help is appreciated, AJAX would be awesome, I'm reading some code right however is a bit confusing.
Thanks in advance.
Update
Here's the entire code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Guess who? - Lobby</title>
<style type="text/css">
.black_overlay{
display: none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: black;
z-index:1001;
-moz-opacity: 0.6;
opacity:.80;
filter: alpha(opacity=80);
}
.white_content {
text-align: center;
display: none;
margin-top: 50px;
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
width: 35%;
height: 500px;
padding: 16px;
border: 16px solid orange;
background: rgba(0,0,0,.8);
z-index:1002;
overflow: auto;
}
input[type="text"]{
width:173px;
display:inline;
margin-left:5px;
}
body { width:960px; margin:0 auto;}
div.chatbox{
position:fixed;
display:table;
border-collapse: collapse;
width: 250px;
height: 350px;
border-radius: 9px;
padding: 0.5em;
background: rgba(0,0,0,.5);
margin-top:25px;
margin-bottom:100px;
margin-right:50px;
margin-left:705px;
}
div.gamebox{
position:fixed;
background: rgba(0,0,0,.5);
width: 630px;
height: 560px;
border-radius: 9px;
padding: 0.5em;
margin-top:25px;
margin-bottom:100px;
margin-right:50px;
margin-left:25px;
}
div.optionbox{
position:fixed;
border-collapse: collapse;
width: 235px;
height: 190px;
border-radius: 9px;
padding: 0.5em;
background: rgba(0,0,0,.5);
margin-top:395px;
margin-bottom:100px;
margin-right:50px;
margin-left:705px;
}
h1 {
margin-top: 10px;
font-family: "Times New Roman", Times, serif;
font-weight: bold;
text-align: center;
font-size: 30px;
color: #F00;
text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white;
}
h2 {
display: inline;
margin-top: 10px;
font-family: "Times New Roman", Times, serif;
font-weight: bold;
text-align: left;
font-size: 25px;
color: #FFF;
}
iframe {
background-color: #FFF;
margin-top: 5px;
margin-bottom: 5px;
margin-left: 5px;
margin-right: 5px;
}
input[type="submit"]{
background-color: #FFF;
margin-top: 1px;
margin-left: 5px;
margin-right: 5px;
}
</style>
<script type="text/javascript">
mostrarPop = function(name) {
document.getElementById(name).style.display='block';
document.getElementById('fade').style.display='block';
}
cerrarPop = function(name) {
document.getElementById(name).style.display='none';
document.getElementById('fade').style.display='none';
}
</script>
</head>
<body background="imagen.jpg" onload="mostrarPop('lightP')">
<div id="lightP" class="white_content">
<h1>Tu personaje secreto es:</h1>
<?php
session_start();
include "config.php";
if(isset($_SESSION["user_name"]))
{
$selectcategoria = "SELECT DISTINCT id_partida, id_categoria FROM partida WHERE user_name =".$_SESSION["user_name"];
$querycategoria = mysqli_query($con, $selectcategoria);
$rowcategoria = mysqli_fetch_array($querycategoria);
$personajenum = rand(0,23);
$selectpersonaje = "SELECT nombre_personaje, foto_personaje FROM Categoria WHERE id_personaje =".$personajenum;
$querypersonaje = mysqli_query($selectpersonaje);
$rowpersonaje = mysqli_fetch_array($querypersonaje);
$selectturno = "SELECT user_name_retador, user_name_oponente FROM WHERE user_name =".$_SESSION["user_name"];
$queryturno = mysqli_query($con, $selectcategoria);
$rowturno = mysqli_fetch_array($query);
if($_SESSION["user_name"]=$rowturno["user_name_oponente"]){
$insertestado = "INSERT INTO estadojugador(id_partida, user_name, turno_activo, personaje_secreto) VALUES(".$row['id_partida'].", ".$_SESSION["user_name"].", "."false".", ".$rowpersonaje["nombre_personaje"].")";
$queryestado = mysqli_query($insertestado);
}
else
{
$insertestado = "INSERT INTO estadojugador(id_partida, user_name, turno_activo, personaje_secreto) VALUES(".$row['id_partida'].", ".$_SESSION["user_name"].", "."true".", ".$rowpersonaje["nombre_personaje"].")";
$queryestado = mysqli_query($insertestado);
}
echo "<img src=\"categorias/".$rowpersonaje["foto_personaje"]."\" width=\"240\" height=\"360\" style=\"display:block; margin: 0 auto;></img>";
}
?>
<button onclick="cerrarPop('lightP')" style="margin-top:10px; margin: 0 auto;">Continuar!</button>
</div>
<div id="lightA" class="white_content" height="300">
<h1>Adivinar...</h1>
<h2>Que personaje escoges?:</h2>
<form type="post">
<input type="text" list="personajes">
<datalist id="personajes" style="display:block">
<?php
session_start();
include "config.php";
if(isset($_SESSION["user_name"]))
{
$select = "SELECT nombre_personaje FROM partida WHERE user_name =".$_SESSION["user_name"]."AND personaje_activo = 'T'";
$query = mysqli_query($con, $select);
$rows = mysqli_num_rows($query);
$cont = 0;
$tableval;
if($rows > 0)
{
while($row = mysqli_fetch_array($query))
{
if($row['personaje_activo'] = "T")
{
=$tableval."<option value=\"".$row['']."\">";
}
}
}
else
{
?>
<?
}
}
echo $tableval;
?>
</datalist>
<button type="submit" action="submit_character.php" name="select" style="display:inline">Elegir!</button>
</form>
<button onclick:"cerrarPop('lightA')">Cancelar</button>
</div>
<div id="fade" class="black_overlay"></div>
<div class="chatbox">
<table width="240" height="250">
<form method="post" action="handler_partidas.php">
<tr>
<td><iframe src="messages_partidas.php" name="iframe" width="230" height="305"></iframe></td>
</tr>
<tr>
<td><input type="text" name="message"> <button type="submit" name="send">Enviar</button>
</tr>
</form>
</table>
</div>
<div class="gamebox">
<table width="240" height="250">
<form method="post" action="fill_table.php">
</form>
</table>
</div>
<div class="optionbox">
<h1>Opciones</h1>
<button onclick="">Rendirse</button>
<button onclick="javascript:mostrarPop('lightA')">Adivinar...</button></br>
<button type="submit" name="yes">Si</button>
<button type="submit" name="no">No</button>
</div>
</body>
</html>
There is 2 problem on your code first one is button onclick event. It should be like;
<button onclick="cerrarPop('lightA')">Cancelar</button>
Second problem is function defination. It is also be like;
cerrarPop = function (name) {
document.getElementById(name).style.display='none';
document.getElementById('fade').style.display='none';
}
jsfiddle link
Related
So I taught myself coding a few years ago, and got it just enough to put together a few tools for work. I recently had to migrate my site out of CodePen and onto an actual web server. Now I'm having an issue where part of my javascript is executing properly (a portion that empties all other input fields when a user enters an input field using JQuery), but the button that calculates an answer will not work. I believe the .click is not picking it up. Either way I'm not getting error messages, the button just does nothing when I press it.
When I put the code in a snippet to share with you guys, it works (just like it did in CodePen), but the exact same code on my web host does not work. I'm really at a loss here and any help would be greatly appreciated. I feel like I'm missing some small line of code that's supposed to be included in all web files.
$(document).ready(function() {
//Clear out input fields when not selected
$("#sg").focusin(function() {
$("#density").val("");
});
$("#density").focusin(function() {
$("#sg").val("");
});
$("#pounds").focusin(function() {
$("#grams").val("");
$("#percentage").val("");
});
$("#grams").focusin(function() {
$("#percentage").val("");
$("#pounds").val("");
});
$("#percentage").focusin(function() {
$("#pounds").val("");
$("#grams").val("");
});
$(".input_field").focusin(function() {
$("#density").removeClass('highlight');
$("#sg").removeClass('highlight');
$("#pounds").removeClass('highlight');
$("#grams").removeClass('highlight');
$("#percentage").removeClass('highlight');
});
//Calculate on press of enter
$("#button").keypress(function(e) {
if (e.which == 13) {
alert("this is working");
}
});
$("#button").click(function() {
calculateButton();
});
//Calculate values on button hit
function calculateButton() {
function numberWithCommas(x) {
x = x.toString();
var pattern = /(-?\d+)(\d{3})/;
while (pattern.test(x))
x = x.replace(pattern, "$1,$2");
return x;
}
function removeCommas(x) {
x = x.replace(",", "");
return x;
}
var results = 0;
//Pulling information from input cells
var densityStr = document.getElementById("density").value;
var sgStr = document.getElementById("sg").value;
var poundsStr = document.getElementById("pounds").value;
var gramsStr = document.getElementById("grams").value;
var percentageStr = document.getElementById("percentage").value;
//remove commas from string and then convert string to number
var densityNum = Number(removeCommas(densityStr));
var sgNum = Number(removeCommas(sgStr));
var poundsNum = Number(removeCommas(poundsStr));
var gramsNum = Number(removeCommas(gramsStr));
var percentageNum = Number(removeCommas(percentageStr));
if (densityStr.length !== 0) {
var sgConversion = densityNum / 8.3454;
$("#sg").val(sgConversion.toFixed(3));
$("#density").addClass('highlight');
} else if (sgStr.length !== 0) {
var densityConversion = sgNum * 8.3454;
$("#density").val(densityConversion.toFixed(3));
$("#sg").addClass('highlight');
}
if (poundsStr.length !== 0) {
$("#pounds").addClass("highlight");
densityNum = document.getElementById("density").value;
var gramsConversion = poundsNum * 119.83;
var percentageConversion = poundsNum / densityNum * 100;
$("#grams").val(gramsConversion.toFixed(0));
$("#percentage").val(percentageConversion.toFixed(2));
} else if (gramsStr.length !== 0) {
$("#grams").addClass("highlight");
densityNum = document.getElementById("density").value;
var poundsConversion = gramsNum / 119.83;
var percentageConversion = poundsConversion / densityNum * 100;
$("#pounds").val(poundsConversion.toFixed(2));
$("#percentage").val(percentageConversion.toFixed(2));
} else if (percentageStr.length !== 0) {
$("#percentage").addClass("highlight");
densityNum = document.getElementById("density").value;
var percentageDec = percentageNum / 100;
var poundsConversion = densityNum * percentageDec;
var gramsConversion = poundsConversion * 119.83;
$("#pounds").val(poundsConversion.toFixed(2));
$("#grams").val(gramsConversion.toFixed(2));
}
}
});
body {
margin: 0;
font-family: 'Lato', sans-serif;
background: #d2d2d2;
}
p {
text-align: center;
}
conatiner {
max-width: 1024px;
margin: 0 auto;
}
#navbarContainer {
background: #F44336;
overflow: hidden;
width: 100%;
margin: 0;
}
.navbar {
float: left;
display: block;
font-family: 'Lato', sans-serif;
height: 40px;
width: 200px;
line-height: 40px;
text-align: center;
background: #F44336;
text-decoration: none;
color: #212121;
}
.navbar:hover {
background: #E57373;
color: white;
}
.active {
background: #C62828;
color: white;
}
#formContainer {
width: 450px;
background: #FDFFFC;
margin: 50px auto;
padding: 0px;
border-radius: 8px;
overflow: hidden;
}
#formContainer header {
width: 100%;
height: 130px;
background-color: #3cba54;
overflow: auto;
color: white;
}
header h1 {
margin: 35px 0 0 0;
text-align: center;
line-height: 30px;
}
header h3 {
line-height: 40px;
text-align: center;
margin: 0;
}
#heading {
background-color: #3cba54;
height: 40px;
color: white;
margin-bottom: 25px;
margin-left: -30px;
}
#heading h3 {
line-height: 40px;
}
form {
padding: 20px 0 0 20px;
text-align: center;
}
label {
display: inline-block;
width: 220px;
text-align: right;
}
#myForm .input_field {
margin-left: 20px;
margin-bottom: 10px;
font-size: 20px;
padding-left: 10px;
width: 125px;
height: 35px;
font-size: 17px;
border-radius: 3px;
background-color: #E0E0E0;
border: none;
}
#button {
display: block;
border-radius: 6px;
width: 200px;
height: 50px;
padding: 8px 15px 8px 15px;
margin: 0 auto;
margin-bottom: 50px;
font-size: 16px;
box-shadow: 0 6px #540000;
background-color: #FF3636;
border: none;
outline: none;
}
#button:active {
background-color: #B81B1B;
box-shadow: 0 1px #27496d;
transform: translateY(5px);
}
.highlight {
background: #FFEB3B !important;
}
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div id="container">
<div id="navbarContainer">
<a class="navbar" id="62" href="https://s.codepen.io/awheat/debug/MpMrEo/yYAyLDjQWgKr">326 IAC 6-2 Tool</a>
<a class="navbar" id="63" href="https://s.codepen.io/awheat/debug/gWmazm/NQkzYnjeQZyA">326 IAC 6-3 Tool</a>
<a class="navbar active" id="voc" href="https://s.codepen.io/awheat/debug/qVpPNm/VGAWNnJYBjZr">VOC Conversion Tool</a>
</div>
<div id="formContainer">
<header>
<h1>VOC Conversion Tool</h1>
<h3>(for conversion of VOC data to other units)</h3>
</header>
<form id="myForm">
<label>Density of Coating (lbs/gal): </label><input type="text" id="density" class="input_field">
<label>Specific Graviy: </label><input type="text" id="sg" class="input_field">
<div id="heading">
<h3>VOC Content</h3>
</div>
<label>Pounds per Gallon (lbs/gal): </label><input type="text" id="pounds" class="input_field">
<label>Grams per Liter (g/L): </label><input type="text" id="grams" class="input_field">
<label>Percentage (%): </label><input type="text" id="percentage" class="input_field"><br><br>
<input type="button" id="button" value="Calculate" autofocus>
</form>
</div>
</div>
</body>
</html>
Sometimes putting script tags before the elements on the page can cause issues. You can try to put the scripts at the bottom of the body like this:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="container">
<div id="navbarContainer">
<a class="navbar" id="62" href="https://s.codepen.io/awheat/debug/MpMrEo/yYAyLDjQWgKr">326 IAC 6-2 Tool</a>
<a class="navbar" id="63" href="https://s.codepen.io/awheat/debug/gWmazm/NQkzYnjeQZyA">326 IAC 6-3 Tool</a>
<a class="navbar active" id="voc" href="https://s.codepen.io/awheat/debug/qVpPNm/VGAWNnJYBjZr">VOC Conversion Tool</a>
</div>
<div id="formContainer">
<header>
<h1>VOC Conversion Tool</h1>
<h3>(for conversion of VOC data to other units)</h3>
</header>
<form id="myForm">
<label>Density of Coating (lbs/gal): </label><input type="text" id="density" class="input_field">
<label>Specific Graviy: </label><input type="text" id="sg" class="input_field">
<div id="heading">
<h3>VOC Content</h3>
</div>
<label>Pounds per Gallon (lbs/gal): </label><input type="text" id="pounds" class="input_field">
<label>Grams per Liter (g/L): </label><input type="text" id="grams" class="input_field">
<label>Percentage (%): </label><input type="text" id="percentage" class="input_field"><br><br>
<input type="button" id="button" value="Calculate" autofocus>
</form>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
Current Situation:
I'm in the process of building a future search box for customer information that is stored in a mysql database. I have the search box working, and pulling correct data. I need the results to be clickable and access links to different pages. I.E. when John Doe is searched, that name will come up below the search box half way between typing. The results (that match whatever is typed) show below the search box and changed based on characters in the box. The results are what I need to be clickable.
Working (but not completed) code for future search:
<?php
$key=$_GET['key'];
$array = array();
$con = mysql_connect ("localhost","username","password");
$db = mysql_select_db ("database",$con);
$query = mysql_query ("SELECT * from customer_table WHERE customerAddress LIKE '%{$key}%'");
while($row=mysql_fetch_assoc($query))
{
$array[] = $row['customerAddress'];
$array[] = $row['customerName'];
}
echo json_encode($array);
?>
I understand this code should be mysqli however I could not get the search to work that way.
Next, is the html file for the search:
<html>
<head>
<title>Customer Search Box</title>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="typeahead.min.js"></script>
<script>
$(document).ready(function(){
$('input.typeahead').typeahead({
name: 'typeahead',
remote:'presearch.php?key=%QUERY',
limit : 10
});
});
</script>
<style type="text/css">
.bs-example{
font-family: sans-serif;
position: relative;
margin: 50px;
}
.typeahead, .tt-query, .tt-hint {
border: 2px solid #CCCCCC;
border-radius: 8px;
font-size: 24px;
height: 30px;
line-height: 30px;
outline: medium none;
padding: 8px 12px;
width: 396px;
}
.typeahead {
background-color: #FFFFFF;
}
.typeahead:focus {
border: 2px solid #0097CF;
}
.tt-query {
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
}
.tt-hint {
color: #999999;
}
.tt-dropdown-menu {
background-color: #FFFFFF;
border: 1px solid rgba(0, 0, 0, 0.2);
border-radius: 8px;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
margin-top: 12px;
padding: 8px 0;
width: 422px;
}
.tt-suggestion {
font-size: 24px;
line-height: 24px;
padding: 3px 20px;
}
.tt-suggestion.tt-is-under-cursor {
background-color: #0097CF;
color: #FFFFFF;
}
.tt-suggestion p {
margin: 0;
}
</style>
</head>
<body>
<div class="row">
<div class=".col-md-6">
<div class="jumbotron">
<h1>Customer Future Search Box <small>Company Name</small></h1>
<button type="button" class="btn btn-primary btn-lg">Home</button>
</div>
</div>
<div class=".col-md-6">
<div class="panel panel-default">
<div class="bs-example">
<input type="text" name="typeahead" class="typeahead tt-query" autocomplete="on" spellcheck="false" placeholder="Type your Query">
</div></div></div></div>
</body>
</html>
What I've tried so far:
In an attempt to make the search results clickable (linked to different pages).
<?php
$key=$_GET['key'];
$array = array();
$con = mysql_connect ("192.169.197.209","azzip_admin","sXf(Z1AKZtT0");
$db = mysql_select_db ("azzip_default",$con);
$query = mysql_query ("SELECT * from customer_table WHERE customerAddress LIKE '%{$key}%'");
while($row=mysql_fetch_assoc($query))
}
?>
<a href= <?php $array[] = $row['customerAddress'];?>
<a href= <?php $array[] = $row['customerName'];?>
<?php
}
echo json_encode($array);
?>
That not only broke my future search, it didn't create any links.
Any help or even pointing in the right direction would be greatly appreciated. Thanks in advance.
This is a page code that shows attendance report of student.I want checkbox in colored if checked green else red.please help me to do this.I tried it but didn't work.Now i can click only on one checkbox that change color.check this image: http://i.stack.imgur.com/JgICk.png
<style>
.checkbox {
margin: 0 0 2em 2em;
}
.checkbox .tag {
color: #595959;
display: block;
float: left;
font-weight: bold;
position: relative;
width: 120px;
}
.checkbox label {
display: inline;
}
.checkbox .input {
display: none;
}
.input + label {
-webkit-appearance: none;
background-color: red;
border: 1px solid #cacece;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
padding: 9px;
display: inline-block;
position: relative;
}
.input:checked + label:after {
background-color: green;
color: #595959;
content: '\2714';
font-size: 10px;
left: 0px;
padding: 2px 8px 2px 2px;
position: absolute;
top: 0px;
}
</style>
<?php
if(isset($_POST["submit"]))
{
//Here goes array
for($i=0;$i<count($_POST['student']);$i++)
{
$name=$_POST['student'][$i];
echo $name;
}
}
?>
</head>
<body >
Report Attendance
<form name="myform" action="" method="post">
<div class="checkbox">
<table border="1" cellspacing="2" cellpadding="5" summary="">
<?php while ($row = mysql_fetch_assoc($res)){?>
<tr><td> <input type="checkbox" class="input" id="input" name="student[]" value="<?php echo $row['stu_id']; ?>" checked="checked" > <?php echo $row['stu_name'] ; ?> <label for="input"></label>
<br/></td></tr>
<?php }?>
</table>
<input type="submit" name="submit" value="submit"/>
</div>
</form>
</body>
</html>
You just need to make id as unique and labels should point to unique id. Here is the jsfiddle with static HTML https://jsfiddle.net/sua2wsm1/
below changes required in your HTML page
<table border="1" cellspacing="2" cellpadding="5" summary="">
<?php while ($row = mysql_fetch_assoc($res)){?>
<tr><td> <input type="checkbox" class="input" id="input<?php echo $row['stu_id']; ?>" name="student[]" value="<?php echo $row['stu_id']; ?>" checked="checked" > <?php echo $row['stu_name'] ; ?> <label for="input<?php echo $row['stu_id']; ?>"></label>
<br/></td></tr>
<?php }?>
Actually, duplicates ID can be the problem. A label is link to an input with the for attribute. So, if you click on the label, it'll be the same as clicking on the input. Your css is hiding the inputs, and using label:after as a box. So, if all inputs have the same id, clicking on a label will not work as expected
I'm trying to append an result from a database PHP insert using echo json_encode($results).
I'm, getting all the values from the post back in the JSON but the appending is not working.
Here's the jQuery side:
$('#postsubmit').click(function(){
error = 0;
// get form data
post = $('#comments').val();
topicname = $('#topicName').val();
topicid = $('#topicID').val();
pageid = $('#pageID').val();
page = $('#page').val();
sendmail = $('#sendmail').val();
galleria_pointer = $('#galleria_pointer').val();
showstatus = $('#showstatus').val();
$(this).attr('disabled','disabled');
if ($("#comments").val() == ''){
$("#comments").css({ "border": "1px solid red"});
$('.hideAdd').show();
$(this).attr('enabled','enabled');
}
$.ajax({
type: "POST",
url: "../foorumi/AjaxPost.php",
dataType: 'text',
data: "topicid="+topicid+"&pageid="+pageid+"&topicname="+topicname+"&page="+page+"&post="+encodeURIComponent(post)+"&sendmail="+sendmail+"&galleria_pointer="+galleria_pointer+
"&showstatus="+showstatus,
beforeSend : function(){
$("#loading_image").show();
$("body").css("cursor", "wait");
},
error : function(XMLHttpRequest, textStatus, errorThrown){
error = 1;
},
success : function(data) {
$("#loading_image").hide();
$("body").css("cursor", "default");
//alert(data);
dataobject = $.parseJSON(data);
var json_post_result = dataobject.post_result;
var json_error_code = dataobject.errors;
var json_topicname = dataobject.topicname;
var json_postid = dataobject.postid;
var json_topicid = dataobject.topicid;
var json_pageid = dataobject.pageid;
var url = dataobject.url;
var json_showstatus= dataobject.showstatus;
var json_post = dataobject.post;
var json_dateNow = dataobject.sentNow;
var json_galleria_pointer = dataobject.sentNow;
var json_data_html = dataobject.data_html;
var decoded = $("<div/>").html(json_data_html).text();
//alert(decoded);
if(json_post_result == true){
url_to = url;
//window.location.replace(url_to);
$(".hideAdd").fadeOut("fast",function(){
$('#ShowNew').show();
$(".divWrapperAppend").append(decoded);
});
}
}
});
});
And here's the PHP side:
$user_ = ($_SESSION['users_id']);
$post_single = utf8_decode($_POST['post']);
$pageid = $_POST['pageid'];
$topicid_ = $_POST['topicid'];
$topicname = $_POST['topicname'];
$page = $_POST['page'];
$galleria_pointer = ($_POST['galleria_pointer']);
$sendmail = ($_POST['sendmail']);
$showstatus = ($_POST['showstatus']);
$microseconds_ = ((double) microtime()) * 1000000;
$results = array();
$errors = '';
$data = array();
$sqluserinfo = "select u.username as username, u.userlevel, (SELECT 1 FROM userphotos up WHERE up.user_= '$user_' and defaultphoto = '1') as photonum
,(SELECT count(1) FROM posts p1 WHERE u.users_id = p1.user_) as usermessagecount FROM users u WHERE u.users_id = '$user_'";
$sqlusersql = mysql_query($sqluserinfo);
$username = mysql_result($sqlusersql, 0, username);
$count_posts = mysql_result($sqlusersql, 0, usermessagecount);
$ulevel = mysql_result($sqlusersql, 0, userlevel);
$photonum = mysql_result($sqlusersql, 0, photonum);
$userSendMailSQL = "select *, (SELECT 1 from mail_topic where sendmail = '1' and user_ = '$user_' and theader_ = '$topicid_') as sendmail1 FROM mail_topic WHERE user_='$user_' and theader_ = '$topicid_' order by id";
$resultsqlquery = mysql_query($userSendMailSQL)or die(mysql_error());
$sendMailto = mysql_result($resultsqlquery, 0, sendmail1);
if ($post_single == "" || strlen(preg_replace('/\W/', '', $post_single)) < 5)
{
$errors = 1;
}
if (!empty($errors)){
$data['errors'] = $errors;
$data['post_success'] = false;
$results = array("errors"=>$errors, "post_result" => $data['post_success']);
}
else{
$data['post_success'] = true;
$new_post = htmlspecialchars($post_single, ENT_QUOTES | ENT_SUBSTITUTE, 'ISO-8859-1');
$insert="insert into posts (topicID, user_, Post, editdate_, updatedmicrosec) values ('$topicid_','$user_','$new_post','editdate_','$microseconds_')";
$timetoday = date("d.m.Y H:i:s");
$dateNow = date_diff_as_text($timetoday,"now") . " sitten";
//Insert data to db
mysql_query($insert);
$postid_ = mysql_insert_id();
if ($sendmail > 0){
sendmail($topicid_,$topicname,$user_,$postid_,$page);
}
updatelastread($topicid_);
$tableStyle_ajax = 'postStyleThisDay';
$tableStyleUser_ajax = 'postStyleThisDayUser';
$tableStyleNoBorder_ajax = 'postStyleThisDayNoBorder';
$styleBorder_ajax = 'style="min-height: 100%; border-right: 2px solid #87b1c8;"';
$aid_ajax = '<a name="'.$postid_.'"></a>';
$idcolor_ajax = 'color: #e82020; font-weight: bold;';
$borderbottom_ajax = 'border-bottom: 2px solid #e82020;';
$bordertop_ajax = 'border-top: 2px solid #e82020;';
if ($photonum > 0)
{
$photodiv = ('<div style="width: 89px; border: 1px solid #dadada; padding: 3px; margin: 0px 5px 5px 0px;"><img src="../profiili/userAlbums/'.$folder.'/'.$thumbnail.'"" style="width: 85px; height: 55px; border: none; padding: 2px;"/></div>');
}
$data_html = ('
<div id="'.$tableStyle_ajax.'" style="min-height: 30px; width: 885px; padding: 5px; margin-top: 5px; '.$bordertop_ajax.'>
<div style="padding: 8px 5px 3px 5px; min-height: 20px; border-bottom: 1px solid #dadada; background-color: #f7fdff;">
<div class="forumPostUser" style="float: left; width: 145px;"><a href="../kayttajat/index.php?id='.$user_.'>'.$username.'</a></div>
<div style="float: left; padding-left: 5px; width: 640px;">Lähetetty: '.$dateNow.'</div>
<div style="float: left; padding-left: 5px; '.$idcolor_ajax.'">ID: '.$postid_.'</div>
</div>
</div>
<div class="column" id="'.$tableStyleNoBorder_ajax.'" style="width: 130px; min-height: 65px; padding: 5px 5px 10px 5px;">
'.$photodiv.'
<div style="font-size: 11px;">Viestejä: '.$count_posts.' kpl</div>
<div style="font-size: 11px; padding-top: 3px;">Taso: '.$showstatus.'
</div>
</div>
<div class="column" id="'.$tableStyleNoBorder_ajax.'" style="min-width: 5px; min-height: 65px; padding: 5px 5px 10px 5px;">
<div> </div>
</div>
<div class="column" id="'.$tableStyleNoBorder_ajax.'" style="width: 730px; min-height: 65px; padding: 5px 5px 10px 5px;">
<span style="font-size: 16px; line-height: 130%;">'.$new_post.'</span>
</div>
<div id="'.$tableStyle_ajax.'" style="min-height: 30px; width: 885px; padding: 5px 5px 5px 5px; margin-top: 5px; '.$borderbottom_ajax.'">
<div style="padding: 8px 5px 3px 0px; min-height: 20px;">
<div style="font-size: 12px; width: 155px; padding-top: 20px; float: left;" class="forumPostUser">alkuun</div>
<div style="float: left; width: 300px; padding-top: 12px; border-top: 1px solid #dadada;"> </div>
<div style="float: left; width: 425px; padding-top: 5px; border-top: 1px solid #dadada;"><div style="float: left; margin-left: 240px;">
<form method="post" action="index.php?id='.$pageid.'&show='.$topicid_ .'&page='.$page.'#quoted"><input type="hidden" name="postID" value="'.$postid_.'" />
<input type="hidden" name="lainaa" value="Lainaa" />
<input type="image" src="../png/lainaa.png" /></form>
</div>
<div style="float: left;">
<form method="post" action="index.php?id='.$pageid.'&show='.$topicid_.'&page='.$page.'&postid='.$postid_.'&tag=#'.$postid_.'"><input type="hidden" name="postID" value="'.$postid_.'" /><input type="hidden" name="muokkaa" value="submit" />
<input type="hidden" name="edited" value="edited" />
<input type="image" src="../png/muokkaa.png" /></form></div>
</div>
</div>
<div style="clear: both;"></div>
</div>
</div>
<div style="clear: both;"></div>');
$data_html = htmlspecialchars($data_html, ENT_QUOTES | ENT_SUBSTITUTE, 'ISO-8859-1');
if (mysql_error() != ""){
echo ('<br><p><center><b><FONT SIZE="-1" FACE="Trebuchet MS,Arial,Helvetica">There was a MySQL Error -- '.mysql_error().'</b></center></p>');
exit;
}
$url = 'http://intra.tobiasfransman.net/foorumi/index.php?id='.$pageid.'&show='.$topicid_.'&page='.$page.'&postid='.$postid_.'&tag=#'.$postid_.'';
$results = array(
"data_html" => $data_html,
"url" => $url,
"post_result" => $data['post_success']
);
}
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
//header('Content-type: application/x-www-form-urlencoded, charset=UTF-8');
echo json_encode($results);
It's the $data_html that I want to append, but it wont append.
Can anyone see what I'm doing wrong?
console log ouput:
{"data_html":"\r\n <div id="postStyleThisDay" style="min-height: 30px; width: 885px; padding: 5px; margin-top: 5px; border-top: 2px solid #e82020;>\r\n <div style="padding: 8px 5px 3px 5px; min-height: 20px; border-bottom: 1px solid #dadada; background-color: #f7fdff;">\r\n <div class="forumPostUser" style="float: left; width: 145px;"><a href="..\/kayttajat\/index.php?id=0>Tobba<\/a><\/div>\r\n <div style="float: left; padding-left: 5px; width: 640px;">Lähetetty: < 1 minuutti sitten<\/div>\r\n <div style="float: left; padding-left: 5px; color: #e82020; font-weight: bold;">ID: 0<\/div>\r\n <\/div>\r\n <\/div>\r\n <div class="column" id="postStyleThisDayNoBorder" style="width: 130px; min-height: 65px; padding: 5px 5px 10px 5px;">\r\n <div style="width: 89px; border: 1px solid #dadada; padding: 3px; margin: 0px 5px 5px 0px;"><a href="..\/kayttajat\/index.php?id=0&album=1&img=2"><img src="..\/profiili\/userAlbums\/\/"" style="width: 85px; height: 55px; border: none; padding: 2px;"\/><\/a><\/div>\r\n <div style="font-size: 11px;">Viestejä: 1104 kpl<\/div>\r\n <div style="font-size: 11px; padding-top: 3px;">Taso: <span>LIFE.IS.A..<\/span>\r\n <\/div>\r\n <\/div>\r\n <div class="column" id="postStyleThisDayNoBorder" style="min-width: 5px; min-height: 65px; padding: 5px 5px 10px 5px;">\r\n <div> <\/div>\r\n <\/div>\r\n <div class="column" id="postStyleThisDayNoBorder" style="width: 730px; min-height: 65px; padding: 5px 5px 10px 5px;">\r\n <span style="font-size: 16px; line-height: 130%;">Testing testing<\/span>\r\n <\/div>\r\n <div id="postStyleThisDay" style="min-height: 30px; width: 885px; padding: 5px 5px 5px 5px; margin-top: 5px; border-bottom: 2px solid #e82020;">\r\n <div style="padding: 8px 5px 3px 0px; min-height: 20px;">\r\n <div style="font-size: 12px; width: 155px; padding-top: 20px; float: left;" class="forumPostUser"><a href="#alkuun">alkuun<\/a><\/div>\r\n <div style="float: left; width: 300px; padding-top: 12px; border-top: 1px solid #dadada;"> <\/div>\r\n <div style="float: left; width: 425px; padding-top: 5px; border-top: 1px solid #dadada;"><div style="float: left; margin-left: 240px;">\r\n <form method="post" action="index.php?id=1&show=41&page=9#quoted"><input type="hidden" name="postID" value="0" \/>\r\n <input type="hidden" name="lainaa" value="Lainaa" \/>\r\n <input type="image" src="..\/png\/lainaa.png" \/><\/form>\r\n <\/div>\r\n <div style="float: left;">\r\n <form method="post" action="index.php?id=1&show=41&page=9&postid=0&tag=#0"><input type="hidden" name="postID" value="0" \/><input type="hidden" name="muokkaa" value="submit" \/>\r\n <input type="hidden" name="edited" value="edited" \/>\r\n <input type="image" src="..\/png\/muokkaa.png" \/><\/form><\/div>\r\n <\/div>\r\n <\/div>\r\n <div style="clear: both;"><\/div>\r\n\r\n <\/div>\r\n <\/div>\r\n <div style="clear: both;"><\/div>","url":"http:\/\/intra.tobiasfransman.net\/foorumi\/index.php?id=1&show=41&page=9&postid=0&tag=#0","post_result":true,"errors":null}
Added $data_html = utf8_decode($data_html) to the php post and now the append works as is :)
In my Application Everything Work Fine add/edit but my main Problem is IF i am on a 'agendaWeek' of Fullcalendar and try to submit or cancel the form then it is going to Month View
Updated Code:
JAVASCRIPT:
<script>
var globalEvent = null;
$(document).ready(function() {
var count=0;
var liveDate=new Date();
var dat = new Date();
var d = dat.getDate();
var m = dat.getMonth();
var y = dat.getFullYear();
var calendar = $('#calendar').fullCalendar({
selectable: true,
selectHelper: true,
select: function(startDate, endDate, allDay, jsEvent, view) {
var startDate1=$.fullCalendar.formatDate(startDate, "yyyy-MM-dd HH:mm:ss");
var endDate1=$.fullCalendar.formatDate(endDate, "yyyy-MM-dd HH:mm:ss");
document.getElementById('mode').innerHTML = "ADD :"+"<img src='<?php echo base_url();?>/assets/images/close.png' style='float:right; height:35px; width:35px; margin-top:-7px;' id='closeimg' name='closeimg'>";
document.getElementById('starting').innerHTML = startDate1;
document.getElementById('ending').innerHTML = endDate1;
$("#ginger").show();
$("#closeimg").click(function(){
$("#ginger").hide();
});
$("#eventName").focus();
$("#submit").click(function(){
var title=$("#eventName").val();
calendar.fullCalendar('renderEvent',{
title: title,
start: startDate1,
end: endDate1,
allDay: false},
true // make the event "stick"
);
var dataString={};
dataString['eventName']=title;
dataString['startTime']=startDate1;
dataString['endTime']=endDate1;
$.ajax({
type : 'POST',
dataType : 'json',
url : '<?php echo base_url(); ?>data/insert',
data: dataString,
success: function(data) {
alert("data insert SuccessFully1");// I get this alert
var currentView = calendar.fullCalendar('getView');
calendar.fullCalendar('refetchEvents');
calendar.fullCalendar('changeView', currentView.name)
calendar.fullCalendar('unselect');
calendar.fullCalendar('refetchEvents');
$("#ginger").hide();
if(data.success){
alert("Data insert suceessfully 2");// i can't get this alert
}
}
});
});
},
});
});
</script>
CSS:
body {
font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 70%;
margin: 0 auto;
}
#popup{
padding-left: 0%; padding-top:17%; display: block; top: 0; left: 37%; z-index:1007; opacity: 1; transform: scale(1);
height: auto;
overflow: auto;
position: absolute;
width:auto;
}
#data{
background-color: #ffffff;
color:#585858;
width:400px;
display:block;
z-index: 100;
padding:0px;
font-family: arial;
font-weight: bold;
border-radius: 7px 7px 0px 0px;
border:1px solid #C5C5C5;
}
#popup textarea{
width:200px;
height:60px;
border-radius: 5px;
vertical-align: top;
}
#detail{
/* display: none;*/
position:fixed;
top:0;
left:0;
z-index:1;
width:100%;
height:100%;
background-color:#000;
filter:alpha(opacity=50);
opacity:.5;
}
.mode{
width:99%;
background-color: #8DB3CC;
background-image:url("<?php echo base_url();?>assets/kendou/styles/textures/highlight.png");
background-position: 0 center;
background-repeat: repeat-x;
height:30px;
padding: 5px 0px 0px 5px;
font-size: 15px;
font-weight:normal;
border-bottom:1px solid #C5C5C5;
border-radius: 7px 7px 0px 0px;
}
.dropdown{
border-style: solid;
border-width: 1px;
padding: 2px 22px 2px 2px;
display: block;
cursor: default;
position: relative;
text-align: right;
line-height:1px;
border-radius: 2px 2px 2px 2px;
color: #2E2E2E;
border-color: #C5C5C5;
}
HTML :
<div class="wrapper">
<div id='calendar'></div>
<div style="display:none;" id="ginger">
<div id="detail"> </div>
<form name="addData" id="addData" action="" method="post">
<div id="popup">
<div id="data">
<div id="mode" value="" class="mode">
<!--<img src="<?php echo base_url();?>/assets/images/close.png" style="float:right;"/>-->
<img src="<?php echo base_url();?>/assets/images/logo.png">
</div><br>
<div style="padding:10px;">
<label for="timing">Timing: <span id="starting"></span> to <span id="ending"></span></label><br><br>
<label for="eventName">Description : </label>
<textarea name="eventName" id="eventName"type="text" value=""></textarea><br><br>
<label for="AgentName"><b>Agent Name*</b></label>
<input name="AgentName" id="AgentName"/>
<label for="UserName">UserName : </label>
<select name="UserName" id="UserName" value=""></select><br><br>
<input type="button"class="k-button" name="submit" id="submit" value="submit">//Changes here
<input type="reset" name="reset" class="k-button" id="reset" value="Reset">//changes here
<input type="button"class="k-button" name="cancel" id="cancel" value="Cancel">//changes here
</div>
</div>
</div>
</form>
</div>
</div>
You can combine getView and changeView:
//remember current view
var currentView = calendar.fullCalendar('getView');
calendar.fullCalendar('refetchEvents');
//set view type
calendar.fullCalendar('changeView', currentView.name)