Passing parameters in onclick of a cell

0

I do not know if it can be done in this way. On my main php page, I load using a loop rows in a table. In one of the cells I have some coordinates, which I need to pass through GET to the mapita.php file. In this loop charge 4 variables, var1 / 2/3/4 (until here everything perfect). This is a fragment of the loop where I load the data in the table:

            echo "    <td class='tabla_t'>". $vasociado . "</td>\n";
            echo "    <td class='tabla_t'>". $vfecha . "</td>\n";
            echo "    <td class='tabla_t'>" . $vnumero . "</td>\n";
            echo "    <td class='tabla_t' onclick=\"'location.href='mapita.php?dato1='". $var1. "' &dato2='". $var2. "' &dato3='". $var3. "' &dato4='". $var4. "'\";>" . $var1 . '-' .$var2 . ' / ' . $var3 . "</td>\n";
            echo "    <td class='tabla_t'>" . substr($vnom . ", " . $vape,0,30) . "</td>\n";

In the mapita.php file I have:

$v1=$_GET['dato1'];
$v2=$_GET['dato2'];
$v3=$_GET['dato3'];
$v4=$_GET['dato4'];

The idea is that by clicking on the cell that I have the onclick, the location is run to another php and the parameters are passed. I do not know with the correct syntax, can it be done like that?

    
asked by look68 18.09.2018 в 15:49
source

1 answer

1

In html if you can click on an element (even in a cell of a table). In general, your problem is because you are not forming the javascript statement well. Your final html should look like:

<table>
<tr>
    <td class='tabla_t'>1</td>
    <td class='tabla_t'>2</td>
    <td class='tabla_t'>3</td>
    <td class='tabla_t' onclick="location.href='mapita.php?dato1=11&dato2=12&dato3=13&dato4=14;'">11-12 / 13</td>
    <td class='tabla_t'>nombre, apellidos, VAPE VAPE</td>
</tr>
</table>

look at the onclick. its value (what it must have in quotes) is a javascript, so it is a sentence. in this case, location.href = ... Therefore, you should NOT start with '(which is a literal). However, when you assign the value to href, this SI has a 'at the beginning and a' at the end. The data does NOT have '(in a uri that character is not admitted, I would exchange it for a literal and your result would contain in the destination said quote)

To see the difference, use your browser's code inspector, and look at the javascript console tab that occurs when you click. If you give an error, it is javascript failure.

    
answered by 18.09.2018 в 17:54