get php boolean and change css border color depends on it?

php

public function livecheck($check_value, $value){ global $connection; $query = "SELECT * FROM users WHERE $check_value = ? LIMIT 1"; $results = $connection->select($query,$value); //return total count $results_exist = $results->rowCount(); $results_exist = $results->fetch(); //if value is more than 0, username is not available if($results_exist) { //out jquery echo echo "We're sorry, that username is not available."; //return fail change border to red $_exist = true; }else{ echo "username is available."; //return true change border to grey $_exist = false; } }

jquery

function checkusername(){ var username_value = $("#username").val(); if (username_value.length >= 4){ //checking the database username exits // $("#user-result").html('<img src="imgs/ajax-loader.gif" />'); // post value isit using it self?// $.post('class/validation.php', {'username':username_value}, function(data) { $("#user-result").html(data); // get the return data from php , fail = red , true = grey $("#username").css(data); }); } return; }

this is a live validation checking my database username and my intention is use jquery to change my css border color depends on my php return Boolean , i was able to echo the Boolean data ,so php check if username exists , border = red , else border = grey.

i hope i explain it right , i cant figure it out where to start this.

--------------Solutions-------------

Don't just send the message from PHP. Send JSON object. And depending on the value of exists inside object change the colour of the textbox.

PHP:

public function livecheck($check_value, $value){
global $connection;

$query = "SELECT * FROM users WHERE $check_value = ? LIMIT 1";
$results = $connection->select($query,$value);

//return total count
$results_exist = $results->rowCount();
$results_exist = $results->fetch();

//if value is more than 0, username is not available
if($results_exist) {
//out jquery echo
$response = array(
"message"=> "We're sorry, that username is not available.",
"exist"=> true
);
// ^^^^^^^^^^^^^^
} else {
$response = array(
"message"=> "username is available.",
"exist"=> false
);
// ^^^^^^^^^^^^^^
}
echo json_encode($response);
}

Javascript:

function checkusername() {
var username_value = $("#username").val();

if (username_value.length >= 4) {
//checking the database username exits
// $("#user-result").html('<img src="imgs/ajax-loader.gif" />');
// post value isit using it self?//
$.post('class/validation.php', {
'username': username_value
}, function (data) {
var usernameAvailable = JSON.parse(data);
$("#user-result").html(usernameAvailable.message);

var color = usernameAvailable.exist ? 'gray' : 'red';

$("#username").css('border-color', color);
});
}
return;
}

You need to return the variable and the text, so you're going to have to use JSON. You need to change this part in your PHP file:

$return = array('text' => '', 'exists' => false);
if($results_exist) {
//out jquery echo
//echo "We're sorry, that username is not available.";
$return['text'] = "We're sorry, that username is not available.";
//return fail change border to red
$return['exists'] = true;
}else{
//echo "username is available.";
$return['text'] = "username is available.";
//return true change border to grey
//$_exist = false;
}
echo json_encode($return);

Then for your JavaScript:

function checkusername(){
var username_value = $("#username").val();

if (username_value.length >= 4){
//checking the database username exits
// $("#user-result").html('<img src="imgs/ajax-loader.gif" />');
// post value isit using it self?//
$.ajax(function() {
type: 'POST',
url: 'class/validation.php',
data: {'username':username_value},
dataType: 'JSON' //This tells the ajax we're expecting a JSON response.
})
.done(function(data) {
$("#user-result").html(data.text);
// get the return data from php , fail = red , true = grey
$("#username").css('border-color', data.exists ? 'grey' : 'red');
});
}
return;
}

So you get the either the values red or grey returned? In that case you should set the css in the following way:

$("#username").css('border-color',data);

Category:php Time:2019-01-10 Views:2
Tags: php css jquery

Related post

  • Special triangle possible with just CSS (so I can change the border color)? 2011-09-21

    I have a sort of speech bubble: http://screencast.com/t/xy3xPHYlM with rounded corners and a triangle on the right of left (depending on :nth-child(odd/even)). The border and rounded corners are no problem with border and border-radius. But I'd like

  • Get selected Row in DataGrid and Change the background color 2011-08-16

    Whenever the user clicks a button I want to get the selected row in a DataGrid and change its background color? I can get the index of the selected row using the SelectedIndex property but I do not know how to change the background of the same. I use

  • How to Change textbox border color and width in winforms? 2011-12-30

    I would like to know how do I change the border color and border width of textbox as something shown below If it is mouse hover I need to display one colour and on mouse down I need to display another colour. Can anyone explain me the detailed proces

  • change checkbox border color 2010-06-15

    can i change border color of checkbox by use css or jquery. i want change only border color of check box. --------------Solutions------------- if you want to do this with pure css, you won't get an result that works in all browsers. if you use jquery

  • Trying to change the Border Color of a label 2009-06-12

    I'm working in VB, VS2008, winforms. I've got some labels to create, and I'm using the BorderStyle = FixedSingle. Is there any way to change the color of this border? It is always defaulting to black. --------------Solutions------------- If you don't

  • How to change the border color of a picturebox (winform)? 2011-03-13

    I want to set the border color/style around the picturebox on and off according to different events. Are there properties or functions that help me to achieve that aim? --------------Solutions------------- Winforms doesn't let you change the border c

  • How to change fancybox border color 2012-02-12

    I've been trying to change fancybox's border color from white. I've succeeded in targeting every part of fancybox except the border. How can I change the color of the fancybox border? --------------Solutions------------- If you're using 1.3.4, the bo

  • How can I change the border color or size of the FIND selection box? The default box is hard to see in my spread sheet where the cells have borders around them. 2014-03-15

    How can I change the border color or size of the FIND selection box? The default box is hard to see in my spread sheet where the cells have borders around them. --------------Solutions------------- Addinar, Until the Excel development team responds t

  • What is the best way to change the border-color of a bootstrap table? 2017-02-22

    I use bootstrap table class. The default border color is grey/silver - I think. But I want to change the border-color to red, but I couldn't get it to work. This is what I have CSS .table { border: red solid 1px !important; } HTML : Table <table clas

  • Windows Mobile/Pocket PC: How do I change the border color of focused/unfocused CEdit, CListCntl, CButton in MFC or Win32 2009-06-10

    How do I change the border color of focused/unfocused CEdit, CListCntl, CButton in WinCE/Windows Mobile 5/6 with MFC or Win32 API? --------------Solutions------------- You can achieve such an effect by deriving your own CEdit class and override WM_NC

  • Changing a border color on a Windows Form 2010-02-01

    Does anybody know how to change the border color of a datagridview in a windows form? --------------Solutions------------- You can't, it is drawn with the color that the user selected in her preferred theme, selected in Control Panel's Display applet

  • How to change the border color of a Grouped UITableView 2010-04-10

    This concerns iPhoneOS-sdk-3.2 I am having difficulty changing the border color of a grouped UITableView. I can change the cell background color, separator color, text color, quite easily now, and the rounded corners clip correctly, even when highlig

  • Is it possible to change the border color of the strip wrapper from the jQuery plugin GalleryView? 2010-04-17

    I found a very nice jquery plugin: http://spaceforaname.com/gallery-light.html I want to change the border color of the strip wrapper (default is white) position: absolute; z-index: 1000; cursor: pointer; top: 304px; left: 74px; height: 98px; width:

  • Flex 3 - Change box border colors 2010-08-09

    I have a question that might seem "basic" but I just cannot figure out how to do it... I have a box and I'd like to change the borderColor. Till there, nothing special. Just a box.bordercolor = xxxxxx... BUT, I'd like to have the top and bottom borde

  • How to change the border color below the navigation bar? 2011-07-25

    Can anyone advise me on how the border below the navigation bar can be changed? I would like to change it from the current black light to a softer color. Appreciate any help here --------------Solutions------------- I do not think there is a method t

  • C# How would I change the border color of a button using the Controls code? 2011-11-23

    This is my code: buttonName = "btn" + y.ToString() + x.ToString(); Control btn = this.Controls.Find(buttonName, true)[0] as Control; btn.BackColor = System.Drawing.Color.Blue; However, I see no border color changing properties, or the like. I used th

  • remove child and change css class of parent 2011-12-18

    I would like to remvoe img tag and change css class of span tag through jquery. and I would like to delete using ID's. I tried using this code Delete a div or span with a id=".xxx" but it didn't work <span id="ctl00_objContentPageTag_spzContactInf

  • How to change the border color (or remove the border) of a PropertyGrid control? 2012-05-03

    Having a standard WinForms 2.0 PropertyGrid control I'm looking for a way to either change the border color of the control or remove the border altogether. I'm aware of the LineColor property which unfortunately only changes the inner borders between

  • Change The Border Color Of Inactive Windows 2013-05-25

    Hi All!! Is there a way to change the border color of inactive windows? Currently mine shows as white/light gray (see image). Thanks!! --------------Solutions------------- No, this can not be done easily at this time. We will have to wait and see if

  • Detection iPhone/iPad and changing CSS file 2011-04-28

    How to detect and change css file iPad,iPhone3G and iPhone 4 with javascript thanks --------------Solutions------------- you can change the CSS file based on the viewport width of device in this way: < link rel="stylesheet" href="stylesheets/css/i

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.652 (s). 13 q(s)