Clear input fields onfocus - input

I'm having problems creating a couple functions to clear an input field onfocus and reset it back to the default text onblur if it's empty. It works fine until you change some of the text and then backspace it out.
My functions are:
function enterField (id, defaultText) {
if (document.getElementById(id).value == defaultText) {
document.getElementById(id).setAttribute("value", "");
document.getElementById(id).style.color = "#000000";
}
}
function leaveField (id, defaultText) {
if (document.getElementById(id).value == "" || document.getElementById(id).value == defaultText) {
document.getElementById(id).setAttribute("value", defaultText);
document.getElementById(id).style.color = "#dddddd";
}
}
And my html is:
<table style="width: 464px; margin-right: -7px; margin-left: -7px; table-layout: fixed;" cellpadding="0" cellspacing="8">
<tr>
<td class="input"><input id="name" type="text" class="name" size="32" value="Name" onfocus="enterField('name', 'Name');" onblur="leaveField('name', 'Name');"></td>
<td class="input"><input id="email" type="text" class="name" size="32" value="Email" onfocus="enterField('email', 'Email');" onblur="leaveField('email', 'Email');"></td>
</tr>
<tr>
<td class="input" colspan="2"><textarea id="message" class="message" rows="8" onfocus="enterField('message', 'Message');" onblur="leaveField('message', 'Message');">Message</textarea></td>
</tr>
<tr>
<td style="text-align: right;" colspan="2"><input id="submit" type="submit" class="button" value="Send"></td>
</tr>
</table>
You can see how it operates at www.ag-designs.ca/index_new.php. Click "Let's Talk" at the bottom.

change
document.getElementById(id).setAttribute("value", defaultText);
to
document.getElementById(id).value = defaultText;
at both occurrences in your functions.

Related

How to pass value to model (Vuejs 3)

in my Vuejs3 project, there is a form in which the new row will be generated by pressing a button, so I put an array to handle new rows then I need to validate inputs, but after validation of the input of the array, the value didn't pass to model, but it works without the validation.. please help me to understand the mistake that I did.
The Form:
<table class="table table-stripped table-border">
<thead>
<tr>
<th>#</th>
<th style="width: 18%">
Medikament <span class="text-danger">*</span>
</th>
<th style="width: 9%">Milligram</th>
<th style="width: 9%">
Packung <span class="text-danger">*</span>
</th>
<th style="width: 7%">
Stück <span class="text-danger">*</span>
</th>
<th style="width: 19%">Apothekenname</th>
<th style="width: 24%">Adresse der Apotheke</th>
<th style="width: 14%">Postleitzahl</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in patientRequestForCreationDtos" :key="index">
<td>{{ index + 1 }}</td>
<td>
<input type="text" v-model="item.drugName" class="form-control" />
</td>
<td>
<input type="number" v-model="item.milligram" class="form-control" />
</td>
<td>
<input type="number" v-model="item.box" class="form-control" />
</td>
<td>
<input type="number" v-model="item.total" class="form-control" />
</td>
<td>
<input type="text" class="form-control" v-model="item.drugStoreName" :readonly="patientDetails.isElga == false" />
</td>
<td>
<input type="text" class="form-control" v-model="item.drugStoreAddress" :readonly="patientDetails.isElga == false" />
</td>
<td>
<input type="text" class="form-control" v-model="item.drugStorePostalCode" :readonly="patientDetails.isElga == false" />
</td>
<td>
<button type="button" #click="deleteRequestItemRow(index)" class="btn btn-sm btn-danger">
-
</button>
</td>
</tr>
</tbody>
</table>
The Array:
patientRequestForCreationDtos: [{
milligram: null,
box: null,
total: null,
drugStoreName: "",
drugStoreAddress: "",
drugStorePostalCode: "",
drugName: "",
}, ],
The validation function:
checkValidation() {
if (!this.patientRequestForCreationDtos.drugName) {
Swal.fire("drug name is required...");
return;
}
return true;
},
```js
---
it always says => drug name is required..
this.patientRequestForCreationDtos is array. maybe you can do this.
checkValidation(patientRequestForCreationDto) {
if (!patientRequestForCreationDto.drugName) {
Swal.fire("drug name is required...");
return;
}
return true;
},
if you'll have only one element in patientRequestForCreationDtos then you gotta choose first element in the array and then check its property
checkValidation() {
if (!this.patientRequestForCreationDtos[0].drugName) {
Swal.fire("drug name is required...");
return;
}
return true
},
also if your patientRequestForCreationDtos is always gonna be an array then you might find this helpful

Error TokenMismatchException in VerifyCsrfToken.php line 68:

I want to do multiple edit, I want to edit from the data I checked following script .blade, I found the TokenMismatchException error in VerifyCsrfToken.php line 68: when updating.
<form name="form" action="{{url('/update-kb')}}" method="post" onsubmit="return deleteConfirm();"/>
<div class="table table-responsive">
<table id="example1" class="table table-bordered">
<thead>
<tr class="info">
<th width="3%"><input type="checkbox" name="select_all" id="select_all" value=""/></th>
<th>No</th>
<th>Data lengkap</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
#foreach( $datasiswa as $row )
<tr>
<td>
<label class="checkbox-inline"><input type="checkbox" name="checked_id[]" class="checkbox" value="{{$row->id}}"/>
</label>
</td>
<td width="5%">{{ $i }}</td>
<td width="95%">
<table class="table">
<tr>
<td class="info">Nama panggilan</td>
<td>{{$row->nm_panggilan}}</td>
<td class="warning">Pekerjaan ibu</td>
<td>{{$row->pekerjaan_ibu}}</td>
</tr>
<tr>
<td class="info">Jenis kelamin</td>
<td>{{$row->jenis_kelamin}}</td>
<td class="warning">No. Handphone</td>
<td>{{$row->hp_ibu}}</td>
</tr>
<tr>
<td class="info">Tempat, Tanggal lahir</td>
<td>{{$row->tempat}}, {{$row->tanggal_lahir}}</td>
<td class="warning">Alamat</td>
<td>{{$row->alamat}}</td>
</tr>
<tr>
<td class="info">Status anak</td>
<td>{{$row->status_anak}}</td>
<td class="warning">Golongan darah</td>
<td>{{$row->goldar}}</td>
</tr>
<tr>
<td class="info">Agama</td>
<td>{{$row->agama}}</td>
<td class="warning">Nama wali</td>
<td>{{$row->nm_wali}}</td>
</tr>
<tr>
<td class="info">Kewarganegaraan</td>
<td>{{$row->kewarganegaraan}}</td>
</tr>
<tr>
<td class="info">Anak ke-</td>
<td>{{$row->anak_ke}}</td>
</tr>
<tr>
<td class="info">Kelas</td>
<td>{{$row->kelas}}</td>
</tr>
</table>
</td>
<td>
<a href="{!! url('/'.$row->id.'/edit-siswa') !!}">
<button class="btn btn-default btn-block"><i class="fa fa-edit"></i></button><br>
</a>
<a href="{!! url('/'.$row->id.'/delete-siswa') !!}">
<button class="btn btn-danger btn-block"><i class="fa fa-trash"></i></button>
</a>
</td>
</td>
</tr>
<?php $i++; ?>
#endforeach
</tbody>
</table>
<div class="col-md-3">
<input type="submit" class="btn btn-danger" name="delete_submit" value="Hapus"/>
</div>
</div>
</form>
But I still have error, what causes it?
public function updatekb($id, Request $request)
{
$data = Datasiswa::find($id);
if (isset($request->delete_submit)) {
$idArr = $request->checked_id;
foreach ($idArr as $id) {
DB::update('update tb_siswa, tb_pernyataan set tb_pernyataan.kelas = "cekcek" where tb_pernyataan.kelas = "TK A" and tb_siswa.sekolah = "KB TK KHALIFAH 25" and id = "' . $id . '" ');
}
return back();
Session::flash('sukses', 'Data berhasil di update', compact('data'));
}
}
Add below to your form element.
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
Some answers are suggesting to disable csrf protection which is possible but NOT RECOMENDED. This leaves your application vulnureable.
Laravel use CSRF token to verify user request. so you have to use it on yevery request if you want to disable it then you can disable it from See here how to disable it or you can use it as
{{ csrf_field() }}
or
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
You can resolve this issue in two ways:-
First One:-
{{ csrf_field() }}
or
<input type="hidden" name="_token" value="{{ csrf_token() }}"/> // add this in form
Or the other (simpler) way, inside your app\Http\Middleware/VerifyCsrfToken.php add
protected $except = [
'update-kb', // your route name
];
Hope it helps!

Issue with Sorting Dataable Date

I've been trying to sort a datatable date column, and I've not been able to successfully get it to work. I've researched and looked at several examples with no luck. The date always sort incorrectly.
The script:
table = $('#FindUserTable')
.on('search.dt', function () {
})
.on('page.dt', function () {
var info = table.page.info();
setTablePaging(info);
})
.on('length.dt', function (e, setting, len) {
var info = table.page.info();
setTablePaging(info);
})
.DataTable({
'paging': true,
responsive: true,
"autoWidth": false,
"language": {
"paginate": {
"next": "<i class='fa fa-chevron-right' style='color:#fff;'></i>",
"previous": "<i class='fa fa-chevron-left' style='color:#fff;'></i>"
}
},
"columnDefs": [
{ "orderable": false, "targets": 3 },
{
type : "date",
"targets": 2,
render: $.fn.dataTable.moment('MM/DD/YYYY')
}
],
"fnDrawCallback": function (evnt) {
$('.dataTables_info').addClass('Hidden');
var rows = $("#FindUserTable").dataTable().fnGetNodes();
var noRecordFound = $('.NoRecordFound ');
if (rows.length === 0 && noRecordFound.length === 1) {
$('.dataTables_empty').text('No record found.');
} else if (rows.length === 0 && noRecordFound.length === 0) {
$('.dataTables_empty').addClass('Hidden');
}
if ($('#FindUserTable_paginate ul.pagination li.paginate_button').size()> 2) {
$('#FindUserTable_paginate')[0].style.display = "block";
} else {
$('#FindUserTable_paginate')[0].style.display = "none";
}
}
});
<table class="table table-responsive table-condensed" id="FindUserTable>
<thead>
<tr role="row"><th style="width:30%" class="sorting_asc" tabindex="0" aria-controls="FindUserTable" rowspan="1" colspan="1" aria-sort="ascending" aria-label="
User Last Name: activate to sort column descending">
<label class="dataTableLabel"> User Last Name</label>
<br>
<div style="padding-bottom:.75em;">
<input class="form-control fullWidth" id="LastName" name="LastName" type="text" value="">
</div>
</th><th style="width:30%" class="sorting" tabindex="0" aria-controls="FindUserTable" rowspan="1" colspan="1" aria-label="
User First Name
: activate to sort column ascending">
<label class="dataTableLabel"> User First Name</label>
<br>
<div style="padding-bottom:.75em;">
<input class="form-control fullWidth" id="FirstName" name="FirstName" type="text" value="pat">
</div>
</th><th style="width:20%" class="sorting" tabindex="0" aria-controls="FindUserTable" rowspan="1" colspan="1" aria-label="
Date Of Birth:
activate to sort column ascending">
<label class="dataTableLabel">Date Of Birth</label>
<br>
<div style="padding-bottom:.75em;">
<input class="form-control fullWidth" data-val="true" data-val-date="The field DOB must be a date." id="DateOfBirth" name="DOB" type="text" value="">
</div>
</th><th style="width:20%; padding-bottom:.7em" rowspan="1" colspan="1">
<a id="searchUser" name="searchUser"><i class="glyphicon glyphicon-search fa-2x"></i></a>
</th></tr>
</thead>
<tbody class="findUserbody">
<tr role="row" class="odd">
<td style="text-align: center;" class="sorting_1"><div class="findUserData"> <input data-value="44" id="44" name="SelectedUser" type="radio" value="44"> Four </div></td>
<td style="text-align: center; "><div class="findUserData">User</div></td>
<td style="text-align: center; "><div class="findUserData"> 05/29/1996</div></td>
<td></td>
</tr><tr role="row" class="even">
<td style="text-align: center;" class="sorting_1"><div class="findUserData"> <input data-value="41" id="41" name="SelectedUser" type="radio" value="41"> One </div></td>
<td style="text-align: center; "><div class="findUserData">User</div></td>
<td style="text-align: center; "><div class="findUserData"> 07/31/2000</div></td>
<td></td>
</tr><tr role="row" class="odd">
<td style="text-align: center;" class="sorting_1"><div class="findUserData"> <input data-value="43" id="43" name="SelectedUser" type="radio" value="43"> Three </div></td>
<td style="text-align: center; "><div class="findUserData">User</div></td>
<td style="text-align: center; "><div class="findUserData"> 10/06/1996</div></td>
<td></td>
</tr><tr role="row" class="even">
<td style="text-align: center;" class="sorting_1"><div class="findUserData"> <input data-value="42" id="42" name="SelectedUser" type="radio" value="42"> Two </div></td>
<td style="text-align: center; "><div class="findUserData">User</div></td>
<td style="text-align: center; "><div class="findUserData"> 05/28/2000</div></td>
<td></td>
</tr></tbody>
</table>
The issue was with the tds that have the dates. There was a div inside the TD which was causing the problem. During sorting, the div is also included as part of the date, and moment.js could not understand the date.

Automating using Selenium

I am trying to find the text from the Select Elements "[New List]". The HTML code behind this is :
<div id="pageBody">
<div class="grid">
<div class="col_12 bgColor column">
<form method="POST" action="pickListEdit.cfm" name="formMain" id="formMain">
<input type="hidden" id="usrAction" name="usrAction" value="NONE"/>
<input type="hidden" id="listtype" name="listtype" value="ACCTS"/>
<input type="hidden" id="listmodified" name="listmodified" value="0"/>
<table cellpadding="0" cellspacing="0" border="0" width="620">
<tbody>
<tr class="alt first last">
<td>
<table cellpadding="0" cellspacing="0" border="0" width="360">
<tbody>
<tr class="alt first">
<td width="150" align="right" class="critH2">
<td height="1" align="left">
<select name="listkey" size="1" onchange="formSubmit('GET');"class="selectfont">
<option value="0">[New List]</option>
</select>
</td>
</tr>
<tr class="alt last">
</tbody>
</table>
</td>
<td width="10"/>
<td width="10"/>
<td valign="top">
</tr>
</tbody>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="600">
</form>
</div>
</div>
</div>
</div>
</body>
The C# code that I am using is :
var AccPic = Driver.Instance.FindElement(By.ClassName("selectfont"));
var selectelement = new SelectElement(AccPic);
selectelement.SelectByText(AP);
The problem is it is unable to find the field name. What I need to do is find the element [New List] and select it. Can someone please help.
Assuming it's the only option tag on the page:
var newList = Driver.Instance.FindElement(By.TagName("option"));
var selectedElement = new SelectElement(newlist);

Input field is filled, but content is not saved using Selenium IDE

Using Selenium IDE, I'm able to fill an input field (using "type" command), but when I "save" the value, this value is lost. Doing the same by hand, everything works fine.
Any hint to solve this issue? I've already tried using typeKeys command.
The code inside the target page is:
<!-- language-all: lang-html -->
<div id="editDiv" class="editDialog">
<table cellspacing="0" width="100%">
<tbody>
<tr>
<td width="25%" style="">period</td>
<td align="right" width="25%" style="padding: 6px;">
<input id="period" type="text" onblur="changeValue(this.id, this.value, undefined)">
<br>
<label>da 0 a 9</label>
</td>
</tr>
</tbody>
</table>
<table cellspacing="0" width="100%">
<input type="button" value="Save" onclick="applyChanges()">
<input type="button" value="Cancel" onclick="removeEditDialog(false)">
</div>
To help more on this issue:
function changeValue(id, value, paramPos) {
var par = tempGlobalParams[id] ? tempGlobalParams[id] : tempGlobalPaintingsParams[paramPos][id];
if(checkRules(id, value, paramPos)){
par.custom = value;
}