PHP table pass to a var in javascript
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have this PHP code and I am trying to alert a table that receives its values via sql.
Here's my code:
<script src="jquery.min.js">
</script>
<script>
function bus(x){
alert("Row index is: " + x.value);
}
</script>
$sql="SELECT ID, NOME, CPF FROM cadastro WHERE NOME LIKE '%" . $name . "%'";
$result=mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($result)){
$ID =$row['ID'];
$NOME=$row['NOME'];
$CPF=$row['CPF'];
echo '<table style="width:100%">';
echo "<tr>";
echo "<th> ID </th>";
echo "<th> NOME </th>";
echo "<th> CPF </th>";
echo "</tr>";
echo '<tr style="cursor: pointer;">';
echo "<td onclick='bus(" . $ID . ")' class='tab'>" . $ID . "</td>";
echo "<td onclick='bus(" . $ID . ")' class='tab'>" . $NOME . "</td>";
echo "<td onclick='bus(" . $ID . )' class='tab'>" . $CPF . "</td>";
echo "</tr>";
echo "</table>";
I need to get the value from the table and serve it to a javascript function.
javascript php
|
show 2 more comments
I have this PHP code and I am trying to alert a table that receives its values via sql.
Here's my code:
<script src="jquery.min.js">
</script>
<script>
function bus(x){
alert("Row index is: " + x.value);
}
</script>
$sql="SELECT ID, NOME, CPF FROM cadastro WHERE NOME LIKE '%" . $name . "%'";
$result=mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($result)){
$ID =$row['ID'];
$NOME=$row['NOME'];
$CPF=$row['CPF'];
echo '<table style="width:100%">';
echo "<tr>";
echo "<th> ID </th>";
echo "<th> NOME </th>";
echo "<th> CPF </th>";
echo "</tr>";
echo '<tr style="cursor: pointer;">';
echo "<td onclick='bus(" . $ID . ")' class='tab'>" . $ID . "</td>";
echo "<td onclick='bus(" . $ID . ")' class='tab'>" . $NOME . "</td>";
echo "<td onclick='bus(" . $ID . )' class='tab'>" . $CPF . "</td>";
echo "</tr>";
echo "</table>";
I need to get the value from the table and serve it to a javascript function.
javascript php
1
alert("Row index is: " + x); no need of .value
– suresh bambhaniya
Nov 23 '18 at 15:27
Could you elleborate more on your question? what are you getting from this code, an error or what?
– Anna Jeanine
Nov 23 '18 at 15:28
The alert shows that the value is undefined
– Matheus Santos
Nov 23 '18 at 15:29
I need the value of the first collumn
– Matheus Santos
Nov 23 '18 at 15:30
undefined because a<td>
does not have a value attribute
– RiggsFolly
Nov 23 '18 at 15:31
|
show 2 more comments
I have this PHP code and I am trying to alert a table that receives its values via sql.
Here's my code:
<script src="jquery.min.js">
</script>
<script>
function bus(x){
alert("Row index is: " + x.value);
}
</script>
$sql="SELECT ID, NOME, CPF FROM cadastro WHERE NOME LIKE '%" . $name . "%'";
$result=mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($result)){
$ID =$row['ID'];
$NOME=$row['NOME'];
$CPF=$row['CPF'];
echo '<table style="width:100%">';
echo "<tr>";
echo "<th> ID </th>";
echo "<th> NOME </th>";
echo "<th> CPF </th>";
echo "</tr>";
echo '<tr style="cursor: pointer;">';
echo "<td onclick='bus(" . $ID . ")' class='tab'>" . $ID . "</td>";
echo "<td onclick='bus(" . $ID . ")' class='tab'>" . $NOME . "</td>";
echo "<td onclick='bus(" . $ID . )' class='tab'>" . $CPF . "</td>";
echo "</tr>";
echo "</table>";
I need to get the value from the table and serve it to a javascript function.
javascript php
I have this PHP code and I am trying to alert a table that receives its values via sql.
Here's my code:
<script src="jquery.min.js">
</script>
<script>
function bus(x){
alert("Row index is: " + x.value);
}
</script>
$sql="SELECT ID, NOME, CPF FROM cadastro WHERE NOME LIKE '%" . $name . "%'";
$result=mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($result)){
$ID =$row['ID'];
$NOME=$row['NOME'];
$CPF=$row['CPF'];
echo '<table style="width:100%">';
echo "<tr>";
echo "<th> ID </th>";
echo "<th> NOME </th>";
echo "<th> CPF </th>";
echo "</tr>";
echo '<tr style="cursor: pointer;">';
echo "<td onclick='bus(" . $ID . ")' class='tab'>" . $ID . "</td>";
echo "<td onclick='bus(" . $ID . ")' class='tab'>" . $NOME . "</td>";
echo "<td onclick='bus(" . $ID . )' class='tab'>" . $CPF . "</td>";
echo "</tr>";
echo "</table>";
I need to get the value from the table and serve it to a javascript function.
javascript php
javascript php
edited Nov 23 '18 at 17:44
iLuvLogix
1,673726
1,673726
asked Nov 23 '18 at 15:26
Matheus SantosMatheus Santos
62
62
1
alert("Row index is: " + x); no need of .value
– suresh bambhaniya
Nov 23 '18 at 15:27
Could you elleborate more on your question? what are you getting from this code, an error or what?
– Anna Jeanine
Nov 23 '18 at 15:28
The alert shows that the value is undefined
– Matheus Santos
Nov 23 '18 at 15:29
I need the value of the first collumn
– Matheus Santos
Nov 23 '18 at 15:30
undefined because a<td>
does not have a value attribute
– RiggsFolly
Nov 23 '18 at 15:31
|
show 2 more comments
1
alert("Row index is: " + x); no need of .value
– suresh bambhaniya
Nov 23 '18 at 15:27
Could you elleborate more on your question? what are you getting from this code, an error or what?
– Anna Jeanine
Nov 23 '18 at 15:28
The alert shows that the value is undefined
– Matheus Santos
Nov 23 '18 at 15:29
I need the value of the first collumn
– Matheus Santos
Nov 23 '18 at 15:30
undefined because a<td>
does not have a value attribute
– RiggsFolly
Nov 23 '18 at 15:31
1
1
alert("Row index is: " + x); no need of .value
– suresh bambhaniya
Nov 23 '18 at 15:27
alert("Row index is: " + x); no need of .value
– suresh bambhaniya
Nov 23 '18 at 15:27
Could you elleborate more on your question? what are you getting from this code, an error or what?
– Anna Jeanine
Nov 23 '18 at 15:28
Could you elleborate more on your question? what are you getting from this code, an error or what?
– Anna Jeanine
Nov 23 '18 at 15:28
The alert shows that the value is undefined
– Matheus Santos
Nov 23 '18 at 15:29
The alert shows that the value is undefined
– Matheus Santos
Nov 23 '18 at 15:29
I need the value of the first collumn
– Matheus Santos
Nov 23 '18 at 15:30
I need the value of the first collumn
– Matheus Santos
Nov 23 '18 at 15:30
undefined because a
<td>
does not have a value attribute– RiggsFolly
Nov 23 '18 at 15:31
undefined because a
<td>
does not have a value attribute– RiggsFolly
Nov 23 '18 at 15:31
|
show 2 more comments
3 Answers
3
active
oldest
votes
You only have one error. onclick
is passing the ID, so the following code will do exactly what you need:
<script>
function bus(x){
alert("Row index is: " + x);
}
</script>
I removed the .value
from your javascript.
function bus(x){
alert("Value is " + x);
}
<table>
<tr>
<td onclick="bus(44)">44</td>
<td onclick="bus(44)">Lorem</td>
<td onclick="bus(44)">ipsum</td>
</tr>
</table>
I need the ID in alert, but i don't receive him. The alert shows "undefined"
– Matheus Santos
Nov 23 '18 at 15:36
see my edit. I added a runnable code.
– Unamata Sanatarai
Nov 23 '18 at 15:39
add a comment |
If x is a Number, then x.value
will give you undefined and you should just use:
alert("Row index is: " + x);
To get the value of the column, you could pass this
to the function instead of the id and then get the innerHTML
:
<td onclick="bus(this)" class="tab">column 1</td>
function bus(elm){
alert(elm.innerHTML);
}
function bus(elm) {
alert(elm.innerHTML);
}
<table>
<tr>
<td onclick="bus(this)" class="tab">column 1</td>
<td onclick="bus(this)" class="tab">column 2</td>
<td onclick="bus(this)" class="tab">column 3</td>
</tr>
</table>
add a comment |
In this case x is not an object, just a plain value so:
alert("Row index is: " + x);
gl, pb
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449309%2fphp-table-pass-to-a-var-in-javascript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You only have one error. onclick
is passing the ID, so the following code will do exactly what you need:
<script>
function bus(x){
alert("Row index is: " + x);
}
</script>
I removed the .value
from your javascript.
function bus(x){
alert("Value is " + x);
}
<table>
<tr>
<td onclick="bus(44)">44</td>
<td onclick="bus(44)">Lorem</td>
<td onclick="bus(44)">ipsum</td>
</tr>
</table>
I need the ID in alert, but i don't receive him. The alert shows "undefined"
– Matheus Santos
Nov 23 '18 at 15:36
see my edit. I added a runnable code.
– Unamata Sanatarai
Nov 23 '18 at 15:39
add a comment |
You only have one error. onclick
is passing the ID, so the following code will do exactly what you need:
<script>
function bus(x){
alert("Row index is: " + x);
}
</script>
I removed the .value
from your javascript.
function bus(x){
alert("Value is " + x);
}
<table>
<tr>
<td onclick="bus(44)">44</td>
<td onclick="bus(44)">Lorem</td>
<td onclick="bus(44)">ipsum</td>
</tr>
</table>
I need the ID in alert, but i don't receive him. The alert shows "undefined"
– Matheus Santos
Nov 23 '18 at 15:36
see my edit. I added a runnable code.
– Unamata Sanatarai
Nov 23 '18 at 15:39
add a comment |
You only have one error. onclick
is passing the ID, so the following code will do exactly what you need:
<script>
function bus(x){
alert("Row index is: " + x);
}
</script>
I removed the .value
from your javascript.
function bus(x){
alert("Value is " + x);
}
<table>
<tr>
<td onclick="bus(44)">44</td>
<td onclick="bus(44)">Lorem</td>
<td onclick="bus(44)">ipsum</td>
</tr>
</table>
You only have one error. onclick
is passing the ID, so the following code will do exactly what you need:
<script>
function bus(x){
alert("Row index is: " + x);
}
</script>
I removed the .value
from your javascript.
function bus(x){
alert("Value is " + x);
}
<table>
<tr>
<td onclick="bus(44)">44</td>
<td onclick="bus(44)">Lorem</td>
<td onclick="bus(44)">ipsum</td>
</tr>
</table>
function bus(x){
alert("Value is " + x);
}
<table>
<tr>
<td onclick="bus(44)">44</td>
<td onclick="bus(44)">Lorem</td>
<td onclick="bus(44)">ipsum</td>
</tr>
</table>
function bus(x){
alert("Value is " + x);
}
<table>
<tr>
<td onclick="bus(44)">44</td>
<td onclick="bus(44)">Lorem</td>
<td onclick="bus(44)">ipsum</td>
</tr>
</table>
edited Nov 23 '18 at 15:37
answered Nov 23 '18 at 15:29
Unamata SanataraiUnamata Sanatarai
4,52431943
4,52431943
I need the ID in alert, but i don't receive him. The alert shows "undefined"
– Matheus Santos
Nov 23 '18 at 15:36
see my edit. I added a runnable code.
– Unamata Sanatarai
Nov 23 '18 at 15:39
add a comment |
I need the ID in alert, but i don't receive him. The alert shows "undefined"
– Matheus Santos
Nov 23 '18 at 15:36
see my edit. I added a runnable code.
– Unamata Sanatarai
Nov 23 '18 at 15:39
I need the ID in alert, but i don't receive him. The alert shows "undefined"
– Matheus Santos
Nov 23 '18 at 15:36
I need the ID in alert, but i don't receive him. The alert shows "undefined"
– Matheus Santos
Nov 23 '18 at 15:36
see my edit. I added a runnable code.
– Unamata Sanatarai
Nov 23 '18 at 15:39
see my edit. I added a runnable code.
– Unamata Sanatarai
Nov 23 '18 at 15:39
add a comment |
If x is a Number, then x.value
will give you undefined and you should just use:
alert("Row index is: " + x);
To get the value of the column, you could pass this
to the function instead of the id and then get the innerHTML
:
<td onclick="bus(this)" class="tab">column 1</td>
function bus(elm){
alert(elm.innerHTML);
}
function bus(elm) {
alert(elm.innerHTML);
}
<table>
<tr>
<td onclick="bus(this)" class="tab">column 1</td>
<td onclick="bus(this)" class="tab">column 2</td>
<td onclick="bus(this)" class="tab">column 3</td>
</tr>
</table>
add a comment |
If x is a Number, then x.value
will give you undefined and you should just use:
alert("Row index is: " + x);
To get the value of the column, you could pass this
to the function instead of the id and then get the innerHTML
:
<td onclick="bus(this)" class="tab">column 1</td>
function bus(elm){
alert(elm.innerHTML);
}
function bus(elm) {
alert(elm.innerHTML);
}
<table>
<tr>
<td onclick="bus(this)" class="tab">column 1</td>
<td onclick="bus(this)" class="tab">column 2</td>
<td onclick="bus(this)" class="tab">column 3</td>
</tr>
</table>
add a comment |
If x is a Number, then x.value
will give you undefined and you should just use:
alert("Row index is: " + x);
To get the value of the column, you could pass this
to the function instead of the id and then get the innerHTML
:
<td onclick="bus(this)" class="tab">column 1</td>
function bus(elm){
alert(elm.innerHTML);
}
function bus(elm) {
alert(elm.innerHTML);
}
<table>
<tr>
<td onclick="bus(this)" class="tab">column 1</td>
<td onclick="bus(this)" class="tab">column 2</td>
<td onclick="bus(this)" class="tab">column 3</td>
</tr>
</table>
If x is a Number, then x.value
will give you undefined and you should just use:
alert("Row index is: " + x);
To get the value of the column, you could pass this
to the function instead of the id and then get the innerHTML
:
<td onclick="bus(this)" class="tab">column 1</td>
function bus(elm){
alert(elm.innerHTML);
}
function bus(elm) {
alert(elm.innerHTML);
}
<table>
<tr>
<td onclick="bus(this)" class="tab">column 1</td>
<td onclick="bus(this)" class="tab">column 2</td>
<td onclick="bus(this)" class="tab">column 3</td>
</tr>
</table>
function bus(elm) {
alert(elm.innerHTML);
}
<table>
<tr>
<td onclick="bus(this)" class="tab">column 1</td>
<td onclick="bus(this)" class="tab">column 2</td>
<td onclick="bus(this)" class="tab">column 3</td>
</tr>
</table>
function bus(elm) {
alert(elm.innerHTML);
}
<table>
<tr>
<td onclick="bus(this)" class="tab">column 1</td>
<td onclick="bus(this)" class="tab">column 2</td>
<td onclick="bus(this)" class="tab">column 3</td>
</tr>
</table>
answered Nov 23 '18 at 15:38
The fourth birdThe fourth bird
25.5k81630
25.5k81630
add a comment |
add a comment |
In this case x is not an object, just a plain value so:
alert("Row index is: " + x);
gl, pb
add a comment |
In this case x is not an object, just a plain value so:
alert("Row index is: " + x);
gl, pb
add a comment |
In this case x is not an object, just a plain value so:
alert("Row index is: " + x);
gl, pb
In this case x is not an object, just a plain value so:
alert("Row index is: " + x);
gl, pb
answered Nov 23 '18 at 15:35
PauloBuenoPauloBueno
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449309%2fphp-table-pass-to-a-var-in-javascript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
alert("Row index is: " + x); no need of .value
– suresh bambhaniya
Nov 23 '18 at 15:27
Could you elleborate more on your question? what are you getting from this code, an error or what?
– Anna Jeanine
Nov 23 '18 at 15:28
The alert shows that the value is undefined
– Matheus Santos
Nov 23 '18 at 15:29
I need the value of the first collumn
– Matheus Santos
Nov 23 '18 at 15:30
undefined because a
<td>
does not have a value attribute– RiggsFolly
Nov 23 '18 at 15:31