Jump to content

Echo javascript


jkkenzie

Recommended Posts

OR

 

<?php
// Some code here

echo <<<END
<script language="javascript">
function validate ( form ) {
    if(form.name.value == ""){
      alert('Please fill in the field');
      form.name.focus();
      return false;
     }
    return true;
  }
</script>
END;

// more code here
?>

Link to comment
https://forums.phpfreaks.com/topic/104717-echo-javascript/#findComment-535958
Share on other sites

There is no need to echo the WHOLE thing...i think it's cleaner this way:

 

<?php
  //code
  $myVar = 'ABC';
?>
<script language="javascript">
function validate ( form ) {
    if(form.name.value == "<?php echo $myVar; ?>"){
      alert('Please fill in the field');
      form.name.focus();
      return false;
     }
    return true;
  }
</script>

Link to comment
https://forums.phpfreaks.com/topic/104717-echo-javascript/#findComment-536081
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.