$(document).ready(function() { // Event handler for Add Stream button $('#addStreamBtn').click(function() { event.preventDefault(); // Prevent default form submission var selectedStream = $('#textStream').val(); if (selectedStream) { // Send selected stream value to the server via AJAX $.ajax({ type: "POST", url: "topicsinputactions?addstream=1;", // Update the URL with the actual server-side script URL data: { stream: selectedStream }, success: function(response) { // Check if the response is successful if (response.success) { // Update the session array on the client-side streams.push(selectedStream); updateTable(); // Update the table } else { alert(response.error); } }, error: function(xhr, status, error) { alert("An error occurred: " + error); } }); } else { alert('Please select a stream first.'); } }); }); // Function to update the table with data from the session variable function updateTable() { var tableBody = $('#streamTable tbody'); tableBody.empty(); // Clear previous rows var row = $(''); row.append($('').text("")); row.append($('').html(' Edit')); row.append($('').html(' Delete')); tableBody.append(row); } if (isset($_GET['addstream'])) { // Add the stream value to the session array $_SESSION['partial_streams'][] = $_POST['stream']; // Return success response echo json_encode(['success' => true]); } else { // Return error response if the stream value is not provided echo json_encode(['error' => 'Stream value is missing.']); } if (isset($_GET['addstream'])) { // Add the stream value to the session array $_SESSION['partial_streams'][] = $_GET['addstream']; // Return success response echo json_encode(['success' => true]); } else { // Return error response if the stream value is not provided echo json_encode(['error' => 'Stream value is missing.']); }