Editor Editor - 2 months ago 43x
HTML Question

Send dynamic SPAN value to PHP script using POST

I am trying to send data from to the using PHP script. I use jqCron My problem is that I have dynamic SPAN value, but value of this span is not being sent using post function. I can not get the value

$TiData = !empty($_POST['BCTiData']) ? $_POST["BCTiData"] : '';
echo $TiData;

This is form

<form id="fo1" action="#" method="post">
<div class="cronMDMtimer"> </div>
<input type="text" class="form-control" id="BCTiData" name="BCTiData" value="<span class="cronMDMtimer-span"></span>">

also I trying this method:

$degerSpan = '<span class="cronMDMtimer-span"></span>'; // Not working

How can I get the data in Span and how can I send with POST?

also I put it here Pastebin


You need to use javascript to extract the value from the SPAN element, then put it in a hidden form field, and then submit the data. This could be done in several ways. Here is some mockup code that should get you started:

<!-- the Span that will contain the data we're interested in -->
<span class="cronMDMtimer-span"></span>

<!-- The HTML Form that will submit the timer value, this is populated using javascript -->
<form onsubmit="myFunction()" id="my-form">
    <input type="hidden" name="timerValue" id="timerValue" value="not yet defined">
    <input type="submit">

// This function gets called once the user submits the form
function myFunction(){

    // First get the value from the cronMDMtimer-span
    timerValue = $('.cronMDMtimer-span').html();

    // Then store the extracted timerValue in a hidden form field

    // submit the form using it's ID "my-form"