Hoi Allen,

ik heb de volgende code:

<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

<?php
include("../../inc/global.php");
// Check online 

// Check in FIGHT

// blabla..>?

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

Hoop dat iemand mij kan helpen, alvast bedankt!
Wat staat er in je HTML-source in je browser?
dit staat in mijn view-source:

                    <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>
De ID is op elke regel hetzelfde.

ID hoort uniek te zijn.

[size=xsmall]Toevoeging op 11/03/2023 11:01:03:[/size]

Gebaseerd op :

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

<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>
super bedankt, hier kan ik verder mee aan de slag. thx!

Reageren