Javascript: empty string - string

How to check if a string is empty in Javascript?
I already used this condition if (res32.trim == "") and if (res32 == "") and didn't work.
res32 is a var res32 = str.subtring(111,112) and can have the following values: spaces, 0, 1, 4, 5, 6 and 7.
if (res32 == " ") {
if (res21 == 000000) {
document.write("<td bgcolor=#99FF00><font face=Verdana color=#FFFFFF size=1>true</font></td></tr>
}
} else {
if (res32 == 0 || res32 ==1 || res32 ==4 || res32 ==5 || res32 ==6 || res32 ==7) {
if (res21 > 0){
document.write("<td bgcolor=#99FF00><font face=Verdana color=#FFFFFF size=1>true</font></td></tr>");
} else {
document.write("<td bgcolor=#FF0000><font face=Verdana color=#FFFFFF size=1>false</font></td></tr>");
}
}
}

Use javascript .value:
function checkValue(){
var res32 = document.getElementById('res32');
if (res32.value == "" || res32.value == null){
alert('The text field is empty.');
}else{
alert('The text field is not empty.');
}
}
<input type="text" id="res32">
<input type="button" onclick="checkValue()" value="Check if the input field is null.">

Related

Gupshup Save response labels of the users in whatsapp

I have an array declared at the beginning and inside my MessageHandler function I capture the responses with if(event.message) and push the message in the array but when it comes to displaying them in a variable called "datos" in a whatsapp message it doesn't work . In the development environment by gupshup it works but when deploying it in whatsapp it doesn't.
var botScriptExecutor = require('bot-script').executor;
var scr_config = require('./scr_config.json');
var arr = [];
function MessageHandler(context, event) {
if (event.message == "Evento" || event.message == "Construccion" || event.message == "Servicio" || event.message == "Evento 1" || event.message == "Construccion 2" || event.message == "Servicio 3") {
json.categ = event.message;
}
if (event.message == "Saltillo" || event.message == "Monterrey" || event.message == "Otro" || event.message == "Saltillo 2" || event.message == "Monterrey 2" || event.message == "Otro 3") {
json.zona = event.message;
}
}
exports.array = json;
in my script defalt.js I work with the label of the "datos" variable
module.exports.datos = {
label_baas: datosSoli
}
var message = require('./index.js');
function datosSoli(options, event, context, callback) {
console.log("---------------------label datosSoli---------------------");
var info = "";
info = "categoria: " + message.array.categ + "zona: " + message.array.zona;
options.next_state = 'label_baaj';
options.data.datos = info;
console.log("-----------options.data.datos-------------", options.data.datos);
callback(options, event, context);
}
This is the flow of my conversation where the "datos" variable module is shown
enter image description here

how to make button stop working once timer is over

i have created a 50 second timer. Once the timer reach zero a pop view will appear displaying the score and the button on the application should stop working but i am not sure how to make the button stop being clickable
equal.setOnClickListener{
++total
if(ans == ans4 || ans1 == ans4 || ans2 == ans4 || ans3 == ans4 || ans == ans5 || ans1 == ans5 || ans2 == ans5 || ans3 == ans5
|| ans == ans6 || ans1 == ans6 || ans2 == ans6 || ans3 == ans6){
answer.setText("Correct")
answer.setTextColor(Color.GREEN)
++correct
score.setText("Score: $correct/$total")
} else {
answer.setText("Wrong")
answer.setTextColor(Color.RED)
score.setText("Score: $correct/$total")
}
}
val timer = object: CountDownTimer(50000, 1000) {
override fun onTick(millisUntilFinished: Long) {
countTimer.setText("Remaining: " + millisUntilFinished / 1000);
if (correct >= 5){
countTimer.setText("Remaining: " + (millisUntilFinished + 10000 ) / 1000);
}
}
override fun onFinish() {
popup()
}
}
timer.start()
}
fun popup(){
var popupView: View = layoutInflater.inflate(R.layout.score, null)
var gameover_textView = popupView.findViewById<TextView>(R.id.endMessage)
gameover_textView.setText("Score: $correct/$total ")
var popupwindow = PopupWindow(this)
popupwindow.contentView = popupView
popupwindow.showAtLocation(popupView, Gravity.CENTER, 0, 100)
popupView.setOnClickListener{
popupwindow.dismiss()
}
}
equal.setClickable(false);
equal.setClickable(true);
//according to the requirement

Laravel pagination with raw query

When I put pagination(50); it shows WhereNull does not exist. and then I go make the whereNull into ctrl + /
and it show the next line which is OrderBy not exist. I seriously dont know where the problem is.. because I want to make pagination without using datatable from a DB::raw query.....
public function searchParticipation(Request $request){
ini_set('memory_limit','2G');
if ($request->method() != 'POST') {
return redirect()->route('ticketparticipation.view');
}
$replaceStartDate = $this->remove_string($request['start_date']);
$replaceEndDate = $this->remove_string($request['end_date']);
$valStartDate = strtotime($replaceStartDate) + (60*60*8);
$valEndDate = strtotime($replaceEndDate) + (60*60*24) + (60*60*8) - 1;
$event_id = $request['event_id'];
$category_id = $request['category_id'];
$ticket_number = $request['ticket_number'];
$full_name = $request['full_name'];
$dataEvent = array(
'event_id' => $event_id,
'category_id' => $category_id,
'ticket_number' => $ticket_number
);
$superadmins = User::UserOrganizer()->get();
$user_id = Session::get('user_id');
$roles = Session::get('roles');
if(empty(Session::get('roles'))){
auth()->logout();
return redirect('/admin/logout2');
}
$eventx = Event::query();
$eventx = $eventx->select('id', 'name');
if ($roles == 'Organizer-Admin') {
$eventx->Where('admin_id','=',$user_id);
$event = $eventx->Where('is_deleted','=','0')->get(); //->Where('is_active','=','1')
}elseif($roles == 'Organizer-Project'){
$eventx->Where('project_manager_id','=',$user_id);
$event = $eventx->Where('is_deleted','=','0')->get(); //->Where('is_active','=','1')
}elseif($roles == 'Organizer-Super-Admin'){
$eventx->Where('superadmin_id','=',$user_id);
$event = $eventx->Where('is_deleted','=','0')->get(); //->Where('is_active','=','1')
}elseif($roles == 'Superadmin-Organizer'){
$event = $eventx->Where('is_deleted','=','0')->get(); //->Where('is_active','=','1')
}
$data = array(
'user_id' => $user_id,
'roles' => $roles,
'date_start' => $request['start_date'],
'date_end' => $request['end_date']
);
if($data['roles'] == 'Organizer-Admin'){
$field = "event.admin_id";
}elseif($data['roles'] == 'Organizer-Project'){
$field = "event.project_manager_id";
}else{
$field = "event.superadmin_id";
}
$tCount = EventParticipation::Select('event_participation.id')
->join('event', 'event.id', '=', 'event_participation.event_id')
->join('categories', 'categories.id', 'event_participation.run_id');
if($event_id != ''){
$tCount = $tCount->Where("event_participation.event_id", "=", $event_id);
}
if($category_id != ''){
$tCount = $tCount->Where("event_participation.run_id", "=", $category_id);
}
if($ticket_number != ''){
$tCount = $tCount->Where(DB::raw('concat(event.ticket_number_prepend,"",event_participation.queue_id)') , '=' , $ticket_number);
}
if($full_name != ''){
$tCount = $tCount->Where("event_participation.full_name", 'LIKE' , '%'.$full_name.'%');
}
$tCount = $tCount->Where("event_participation.acceptance_date", "<>", 0)
->Where("event_participation.is_participating", "=", 1)
->Where("event_participation.is_deleted", "=", 0)
->OrderBy('event_participation.creation_date','ASC')
->get();
$eventDetail = Event::Select('name', 'registration_end', 'type','primary_currency')->Where('id', '=', $event_id)->first();
if($tCount->count() < 10000) {
$ticketParticipation = EventParticipation::Select(
DB::raw("if(epu.full_name is not null, epu.full_name, event_participation.full_name) as full_name"),
DB::raw("if(epu.address is not null, epu.address, event_participation.address) as address"),
DB::raw("if(epu.city is not null, epu.city, event_participation.city) as city"),
DB::raw("if(epu.postcode is not null, epu.postcode, event_participation.postcode) as postcode"),
DB::raw("if(epu.state is not null, epu.state, event_participation.state) as state"),
DB::raw("if(epu.country is not null, epu.country, event_participation.country) as country"),
DB::raw("if(epu.additional_info is not null, epu.additional_info, event_participation.additional_info) as additional_info"),
'event_participation.id', 'event_participation.delivery_company', 'event_participation.tracking_number', 'event_participation.run_id','event_participation.event_id', 'event_participation.local_transaction_number', 'event_participation.user_id',
'event_participation.nric_passport', 'event_participation.gender', 'event_participation.tshirt_size', 'event_participation.nationality',
'event_participation.email', 'event_participation.contact_number', 'event_participation.emergency_contact_name', 'event_participation.emergency_contact_number', 'event_participation.medical_conditions', 'event_participation.amount',
'event_participation.after_discount', 'event_participation.discount_id', 'event_participation.payment_type', 'event_participation.remarks',
'event.name AS eventname', 'event.ticket_number_prepend', 'categories.title AS run_title', 'event_participation.date_of_birth', 'event_participation.creation_date', 'event_participation.acceptance_date',
DB::raw("FROM_UNIXTIME(`event_participation`.`creation_date`,\"%d-%m-%Y %h:%i:%s %p\") AS `register_date`"),
DB::raw("CONCAT(event.`ticket_number_prepend`, '', event_participation.`queue_id`) AS `ticket_number`"),
'virtual_parcel_shipping_order.awb_id','virtual_parcel_shipping_order.awb_url','virtual_parcel_shipping_order.tracking_url','virtual_parcel_shipping_order.shipping_status',
'virtual_parcel_shipping_order.pick_up_date','virtual_parcel_shipping_order.parcel_content',
'virtual_parcel_shipping_order.status','virtual_parcel_shipping_order.response')//DB::raw("FROM_UNIXTIME(`event_participation`.`date_of_birth`,\"%d-%m-%Y\") AS `dob`"),
->join('event', 'event.id', '=', 'event_participation.event_id')
->join('categories', 'categories.id', 'event_participation.run_id')
->leftjoin('event_participation_report_status','participation_id','event_participation.id')
->leftjoin('virtual_parcel_shipping_order','participant_id','event_participation.id')
->leftjoin('event_participation_utf8 as epu', 'event_participation.id', 'epu.participation_id')->paginate(50); <<<<<<<< got problem when I add in paginate(50)
if($event_id != ''){
$ticketParticipation = $ticketParticipation->Where("event_participation.event_id", "=", $event_id);
}
if($category_id != ''){
$ticketParticipation = $ticketParticipation->Where("event_participation.run_id", "=", $category_id);
}
if($ticket_number != ''){
$ticketParticipation = $ticketParticipation->Where(DB::raw('concat(event.ticket_number_prepend,"",event_participation.queue_id)') , '=' , $ticket_number);
}
if($full_name != ''){
$ticketParticipation = $ticketParticipation->Where("event_participation.full_name", 'LIKE' , '%'.$full_name.'%');
}
$ticketParticipation = $ticketParticipation->Where("event_participation.acceptance_date", "<>", 0)
->Where("event_participation.is_participating", "=", 1)
->Where("event_participation.is_deleted", "=", 0)
->WhereNull("event_participation_report_status.participation_id")
->OrderBy('event_participation.queue_id', 'DESC')
->get()->chunk(1000);
$eventDiscount = EventDiscountCode::Select('id', 'event_id', 'amount', 'code')->Where('event_id', $event_id)->get();
return view('admin.organizer.participant_summary',['ticketParticipation'=>$ticketParticipation], compact('event', 'ticketParticipation', 'eventDiscount', 'dataEvent', 'eventDetail'));
}else{
return view('admin.organizer.participant_summaryv2', compact('event','data', 'dataEvent', 'eventDetail'));
}
}
I am seriously not sure where is the problem.....

How to use Session thru Login, Authorization,Authentication?

First of all i am a newbie when it comes to programming and i am only self-learning and would like to ask for solutions that i have encountered and can't be solved by my own
I Can't make it work. i would like Session["userlevel"] == "Admin" to be the only one to access the view how can i make this to work please help..
public ActionResult Authorize(Test user)
{
using (TableEntities db = new TableEntities())
{
var loginUserAdmin = db.Employees.Where(x => x.Username == user.Username && x.UserPassword == user.UserPassword && x.AccountStatus == "Active" && x.AccountType == "Admin").FirstOrDefault();
if (loginUserAdmin == null || loginUserAdmin != loginUserAdmin)
{
var loginUserStaff = db.Employees.Where(x => x.Username == user.Username && x.UserPassword == user.UserPassword && x.AccountStatus == "Active" && x.AccountType == "Staff").FirstOrDefault();
if(loginUserStaff == null || loginUserStaff != loginUserStaff)
{
var loginUserUser = db.Employees.Where(x => x.Username == user.Username && x.UserPassword == user.UserPassword && x.AccountStatus == "Active" && x.AccountType == "User").FirstOrDefault();
if(loginUserUser== null || loginUserUser != loginUserUser)
{
var loginUserAdmin1 = db.Employees.Where(x => x.Username == user.Username && x.UserPassword == user.UserPassword && x.AccountStatus == "Inactive" && x.AccountType == "Admin").FirstOrDefault();
if (loginUserAdmin1 ==null || loginUserAdmin1 != loginUserAdmin1)
{
var loginUserStaff1 = db.Employees.Where(x => x.Username == user.Username && x.UserPassword == user.UserPassword && x.AccountStatus == "Inactive" && x.AccountType == "Staff").FirstOrDefault();
if(loginUserStaff1 == null || loginUserStaff1 != loginUserStaff1)
{
var loginUserUser1 = db.Employees.Where(x => x.Username == user.Username && x.UserPassword == user.UserPassword && x.AccountStatus == "Inactive" && x.AccountType == "User").FirstOrDefault();
if (loginUserUser1 == null || loginUserUser1 != loginUserUser1)
{
ViewBag.LoginError = "Invalid Credentials";
return View("Login");
}
else
{
ViewBag.LoginError = "Inactive User Account";
return View("Login");
}
}
else
{
ViewBag.LoginError = "Inactive Staff Account";
return View("Login");
}
}
else
{
ViewBag.LoginError = "Inactive Administrator Account";
return View("Login");
}
}
else
{
ViewBag.Messageko = "User";
return RedirectToAction("Dashboard");
}
}
else
{
ViewBag.Messageko = "Staff";
Session["userid"] = loginUserStaff.EmployeeID;
Session["firstName"] = loginUserStaff.FirstName;
Session["lastName"] = loginUserStaff.LastName;
Session["userName"] = loginUserStaff.Username;
Session["userPassword"] = loginUserStaff.UserPassword;
Session["userlevel"] = loginUserStaff.AccountType;
return RedirectToAction("Dashboard" , "Test", user);
}
}
else
{
ViewBag.Messageko = "Admin";
Session["userid"] = loginUserAdmin.EmployeeID;
Session["firstName"] = loginUserAdmin.FirstName;
Session["lastName"] = loginUserAdmin.LastName;
Session["userName"] = loginUserAdmin.Username;
Session["userPassword"] = loginUserAdmin.UserPassword;
Session["userlevel"] = loginUserAdmin.AccountType;
ViewBag.acc = loginUserAdmin.AccountType;
return RedirectToAction("Dashboard", "Test" ,"Login");
}
this is my Dashboard Controller
[HttpGet]
public ActionResult Dashboard()
{
TableEntities db = new TableEntities();
ViewBag.Active = db.Employees.Where(x => x.AccountStatus == "Active");
ViewBag.Message = "GG";
return View();
}
And this is my View
#{
ViewBag.Title = "Dashboard";
Layout = "~/Views/Shared/_Layout.cshtml";
}
#if (Session["userlevel"].ToString() == "Admin")
{
Response.Redirect("~/Test/Login");
}
else
{
if (ViewBag.Active != null)
{ <label style="font-size:12px; color:red;">#ViewBag.Messageko</label>
<table class="table table-striped">
<tr>
<th>EmployeeID</th>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>User Name</th>
<th>User Password</th>
<th>Account Status </th>
</tr>
#foreach (var User in ViewBag.Active)
{
<tr>
<td align="center">#User.EmployeeID</td>
<td align="center">#User.FirstName</td>
<td align="center">#User.MiddleName</td>
<td align="center">#User.LastName</td>
<td align="center">#User.Username</td>
<td align="center">#User.UserPassword</td>
<td align="center" class="text-success">#User.AccountStatus</td>
</tr>
}
</table>
}
}
Thank you Very Much
In Visual Studio 2015 #if (Session["userlevel"].ToString() == "Admin") works!!
But in 2017 i dont know but
#if (Session["userlevel"].ToString().Trim() == "Admin") works!!

jQuery-Validation-Engine required only if value of another field is x or y

"requiredInFunction": {
"regex": "none",
"func": function(field, rules, i, options){
if (field.val() === '' && $('#CartItem_vision').val()==="Progressive") {
return false;
}
if (field.val() === '' && $('#CartItem_vision').val()==="Bifocal")
{
return false;
}
else
{
return true;
}
},
"alertText": "Addition is Required"
},
validate[custom[requiredInFunction]]
This validation does not do anything.
unless I put validate[required, custom[requiredInFunction]], but it becomes required even if the CartItem_vision is not "Progressive" or "Bifocal". I want them to be only required if value is "Progressive" or "Bifocal".
In your function you can add
rules.push('required');
Like this :
function checkCell(field, rules, i, options){
if ($('#cellNum').val().length > 0 && field.val().length == 0) {
rules.push('required');
return "Provider necessary with phone number";
}
}
This means that if #cellNum is populated then the provider is necessary.
The initialization is :
<select name="provider" id="provider" class="validate[funcCall[checkCell]">

Resources