JS combi met php
ik heb de volgende code:
Code (php)
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
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>
<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)
Hoop dat iemand mij kan helpen, alvast bedankt!
Wat staat er in je HTML-source in je browser?
Code (php)
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
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>
<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>
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)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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>
<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!