Wednesday, 15 April 2015

javascript - How to use JS confirm within a conditional PHP statement? -



javascript - How to use JS confirm within a conditional PHP statement? -

php executed first before js, there easy way output confirmation dialog (like javascript confirmation) if info not empty in conditional php statement:

<?php if (!empty($data)) { //data not empty //ideally want show confirmation dialog in part user //to confirm if user wants overwrite existing info //if user confirms //overwrite existing info here } else { //data empty,proceed other task //don't show dialog }

i don't want add together form user, simple confirmation dialog js confirm. or there php replacement function this? thanks.

i separate info , code, create js variable php

// utilize json_encode when creating js variables php avoid // encoding issues new lines , quotes. var isdataempty = <?php echo json_encode(empty($data)); ?>; if (!isdataempty) { if (confirm("some message")) { overwriteexistingdata(); } } else { // proceed }

php javascript

No comments:

Post a Comment