简体   繁体   中英

How to get value of hidden filed which is set in javascript

I have a hidden field. When user click on a button (here delete button) its value is set is as one in java script.Now I want to get its value on posting the input field - submit . My code is here.

 <input type="hidden" name="clicked_delete_btn"  id="clicked_delete_btn" value=""/>
 <input type="button" name='delete' id='delete' value="Delete" onClick="return confirm_delete(this);"> 
 <input type="submit" name="update" value="UPDATE"  >  

javascript

function confirm_deleteo(ele) {
    if (confirm('Do you wish to delete the file?')) {
        ele.style.display = 'none';
        document.getElementById('clicked_delete_btn').value = 1;
        return true;
    } else return false;
}

php code

if(isset($_POST['update'])) {
    $delete_clicked=$_POST['clicked_delete_btn'];
    if($delete_clicked==1) {
        //do operations
    }
}

But it's value is not getting on $_POST['update'].

您需要使用ID而不是名称

 document.getElementById('clicked_photo_delete_btn').value = 1; 

I have tried to assemble your code and it works fine on my system:

http://pastebin.com/NAEYAZre , http://pastebin.com/3vEsrHJJ

Check your form tag options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM