У меня есть HTML-код. Я хочу реализовать onclick
для имени кнопки GET DATA
в моем HTML-коде. Также я хочу отправить userId
и categoryId
данные в файл php, когда я нажимаю на кнопку GET DATA
Пожалуйста, добавьте это в мой код. Вот мой код
<html>
<header>
<title>Hello World
</title>
</header>
<body>
<!--javascript make append table data-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script>
$(function() {
var user = document.getElementById("userId").value;
var category = document.getElementById("categoryId").value;
alert (user);
alert (category);
$.getJSON('myphp.php',{"userId":'user',"categoryId":'category'}, function(data) {
$.each(data.videoLectureListing, function(i, f) {
var link = "https://www.youtube.com/embed/"+ f.video;
var tblRows = "<tr>" + "<td>" + f.videoName + "</td>" + "<td>" + f.date + "</td>" + "<td>" + f.time + "</td>" + "<td>" + f.videoDuration + "</td>" + "<td><a target='_blank' href='"+link+"'>"+link+"</a></td>" + "</tr>";
$(tblRows).appendTo("#userdata tbody");
});
});
});
</script>
<!--javascript append table data ended -->
<!-- user form -->
<form method='GET'>
<label for="userId"><b>UserId</b></label>
<input id='userId' type="number" placeholder="Enter Your User Id" name="userId" autofocus required>
<label for="categoryId"><b>categoryId</b></label>
<input id='categoryId' type="number" placeholder="Enter categoryId" name="categoryId" required>
<button type="submit" >GET DATA</button>
</form>
<!-- user form -->
<!--table-->
<div class="wrapper">
<div class="profile">
<table id= "userdata" width="100%" border="5">
<thead>
<th>VIDEO NAME</th>
<th>DATE</th>
<th>TIME</th>
<th>DURACTION</th>
<th>LINK </th>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<!--table data end-->
</body>
</html>