Page 1 of 1

I need a little help

Posted: 2020-03-28 13:18
by dgasparin
Hello to everyone,
I'm very new about PHP and JavaScript.
I need your help about a simple question, simple for you not for me.
The target is in the same table I have to copy a field in another one using a button.
I wrote this :
$j(function() {
$j(
'<div class="btn-group-vertical btn-group-lg vspacer-lg" style="width: 100%;">' +
'<button type="button" class="btn btn-primary btn-lg">' +
'<i class="glyphicon glyphicon-list-alt"></i> Check Heart Rate' +
'</button>' +
'</div>'
).appendTo('.detail_view .btn-toolbar');
$j("reqhr").clone().appendTo("command");
If I wrote rightly, now I need a string to execute the last string when I click the button
Could you please help me?
Thank you so much

Re: I need a little help

Posted: 2020-03-28 17:36
by pbottcher
Hi,

as I cannot say if the statement $j("reqhr").clone().appendTo("command"); will work, ( I would guess it does not as your selectors seem odd)
and I do not have the information about your fields (and fieldtype) I can only provide parital information.
You could try something like the below for your button. Keep in mind, that every time the user will click the butten the copy function will be called.

Code: Select all

function copy() {
	<!-- put here the code you need to copy your data -->
}
$j(function() {

$j(
'<div class="btn-group-vertical btn-group-lg vspacer-lg" style="width: 100%;">' +
'<button id="bc" onclick="copy()" type="button" class="btn btn-primary btn-lg">' +
'<i class="glyphicon glyphicon-list-alt"></i> Check Heart Rate' +
'</button>' +
'</div>'
).appendTo('.detail_view .btn-toolbar');
});

Re: I need a little help

Posted: 2020-03-29 08:04
by dgasparin
Thank you so much for your help.
I really appreciate.
I will test now
Thank you

Re: I need a little help

Posted: 2020-03-29 08:37
by dgasparin
I beg your pardon disturbing you now.
Just to explain better the situation, I need to copy the string inside the reqhr to the string called command.
How can I do this?
Thank you so much for your big patience, availability and kindness
Best regards
Davide
Best regards

Re: I need a little help

Posted: 2020-03-29 10:48
by pbottcher
Hi,

what fields are reqhr and command? input fields? maybe you can post a screenshot.

at a first shot you may try $j('#command').val($j('#reqhr').val()) to copy.

Re: I need a little help

Posted: 2020-03-29 12:03
by dgasparin
Thank you for your answer.
I put here the screenshoot of both.
Basically reqhr is an autofill field. It is automatically made when I put values in other fields.
command in a text filed where I have to copy reqhr
Thank you so much for your help
Davide

Re: I need a little help

Posted: 2020-03-29 12:51
by pbottcher
ok, thanks, so in that case you can try

$j('#command').val($j('#reqhr').text().trim());

Re: I need a little help

Posted: 2020-03-29 12:59
by dgasparin
Dear pböttcher, you are my hero.
Thank you so much
It is working
Thank you

Re: I need a little help

Posted: 2020-03-31 09:02
by dgasparin
Good morning
I apologise disturbing you today.
I need a help yet about this.
The target is the same, to copy a string inside a mysql field.
Using your advice I sorted out the problem but I faced other new:
  • I can hide the fields on the webpage because if they are not visible, rightly , the function doesn't works and I can't leave the visible.
So to sort out the problem I changed way using a direct access to the DB. To do this I wrote two different files:
  • .js file to make the button and to call the .php file
  • .php file to make the string using the db data
This is the php file and I have a problem. The program works rightly but inside the wid the are a lot of data and I need to read only one. The wid connected to the customer.
Could you helo me to add the right filter to select the right wid please?
Thank you so much
Davide
<?php
$code=",073#";
$code1="IXL,";
$row= ["wid"];

$servername = "localhost";
$database = "c1ms";
$username = "c1us";
$password = "test";

// Create connection

$conn = mysqli_connect($servername, $username, $password, $database);
$sql = "SELECT wid FROM patients";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $codeheart."".$row["wid"]."".$code. "<br>";
}
}
?>