JS combi met php

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Rick kem

rick kem

10/03/2023 21:54:24
Quote Anchor link
Hoi Allen,

ik heb de volgende code:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
                    <script>
                    $(document).ready(function(){
                        $("change").click(function(){
                            // Get value from input element on the page
                            var numValue = $("#num").val();
                            
                            // Send the input data to the server using get
                            $.get("attack_map/ajax_call/change.php", {id: numValue} , function(data){
                                // Display the returned data in browser
                                $("#result").html(data);
                            });
                        });
                    });
                    </script>
                    <?php
                    $sqlBattle
= $connect->runQuery("SELECT * FROM users_battle WHERE user_id = '".$connect->clearText($getUserdata->id)."'");
                    while($row = $connect->FetchObject($sqlBattle)){
                    ?>

                        <input type="hidden" id="num" name ="num" value="<?php echo $connect->Filter($row->id); ?>" />
                        <button type="change"><img src="images/<?php echo $connect->Filter($row->_id); ?>.gif" height="32px" width="32px" /></button>
                    <?php
                    }
                    ?>

                    <div id="result">
        
    </div>


Echter geeft die op welke button ik ook klik, altijd het ID 1 aan...

change.php
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
<?php
include("../../inc/global.php");
// Check online

// Check in FIGHT

// blabla..>?

//

$id = $_GET['id'];
echo $id;
?>

Hoop dat iemand mij kan helpen, alvast bedankt!
 
PHP hulp

PHP hulp

19/03/2024 06:20:06
 
- Ariën  -
Beheerder

- Ariën -

10/03/2023 22:02:05
Quote Anchor link
Wat staat er in je HTML-source in je browser?
 
Rick kem

rick kem

11/03/2023 09:06:03
Quote Anchor link
dit staat in mijn view-source:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
                    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
                    <script>
                    $(document).ready(function(){
                        $("button").click(function(){
                            // Get value from input element on the page
                            var numValue = $("#num").val();
                            
                            // Send the input data to the server using get
                            $.get("attack_map/ajax_call/change.php", {id: numValue} , function(data){
                                // Display the returned data in browser
                                $("#result").html(data);
                            });
                        });
                    });
                    </script>
                                            <input type="hidden" id="num" name ="num" value="1" />
                        <button type="change"><img src="images/1.gif" height="32px" width="32px" /></button>
                                            <input type="hidden" id="num" name ="num" value="2" />
                        <button type="change"><img src="images/5.gif" height="32px" width="32px" /></button>
                                            <input type="hidden" id="num" name ="num" value="3" />
                        <button type="change"><img src="images/6.gif" height="32px" width="32px" /></button>
                                            <input type="hidden" id="num" name ="num" value="4" />
                        <button type="change"><img src="images/149.gif" height="32px" width="32px" /></button>
                                            <input type="hidden" id="num" name ="num" value="5" />
                        <button type="change"><img src="images/11.gif" height="32px" width="32px" /></button>
                                            <input type="hidden" id="num" name ="num" value="6" />
                        <button type="change"><img src="images/15.gif" height="32px" width="32px" /></button>
                                        <div id="result">
        <h2>Content of the result DIV box will be replaced by the server date and time</h2>
    </div>
    <button type="button">Load Date and Time</button>
 
Adoptive Solution

Adoptive Solution

11/03/2023 09:51:52
Quote Anchor link
De ID is op elke regel hetzelfde.

ID hoort uniek te zijn.

Toevoeging op 11/03/2023 11:01:03:

Gebaseerd op :

https://stackoverflow.com/questions/10578566/jquery-this-id-return-undefined

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>

<script>
$(document).ready(function(){
    $("button").click(function(){
        // Get value from input element on the page
        //var numValue = $("#num").val();
        var numValue = 'object is ' + $(this).attr("id");
        alert( this.id + ' of ' + numValue );
        //Send the input data to the server using get
        //$.get("attack_map/ajax_call/change.php", {id: numValue} , function(data){
            // Display the returned data in browser
            //$("#result").html(data);
        //});
    });
});
</script>

<button type="change" id="num1"><img src="images/1.gif"  height="32px" width="32px" /></button>
<button type="change" id="num2"><img src="images/6.gif"  height="32px" width="32px" /></button>
<button type="change" id="num3"><img src="images/11.gif" height="32px" width="32px" /></button>
<button type="change" id="num4"><img src="images/15.gif" height="32px" width="32px" /></button>
 
Rick kem

rick kem

11/03/2023 11:32:58
Quote Anchor link
super bedankt, hier kan ik verder mee aan de slag. thx!
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.