Styles2304 Posted June 3, 2009 Share Posted June 3, 2009 I'm populating a form and, in the process, trying to show/hide certain divs based on whether or not certain radio buttons are marked as checked. Am I missing something that is causing the toggleDisplay code being called by the PHP to not execute? <input type="radio" name="Mil_Status" value="ETS" onclick="toggleDisplay('show', 'Mil_FromTo', 'main'); toggleDisplay('hide', 'Mil_Serving', 'main'); toggleDisplay('hide', 'Mil_Discharge', 'main');" <?php if ($Mil_Status == 'ETS') { echo 'Checked'; ?>> <?php echo "<script type='text/javascript'>toggleDisplay('show', 'Mil_FromTo', 'main'); toggleDisplay('hide', 'Mil_Serving', 'main'); toggleDisplay('hide', 'Mil_Discharge', 'main');</script>"; } ?> ETS or Retired <br> Link to comment https://forums.phpfreaks.com/topic/160788-calling-javascript-function-from-php/ Share on other sites More sharing options...
Ken2k7 Posted June 3, 2009 Share Posted June 3, 2009 Your input tag is never closed. And I don't know how you want that function to trigger, so this is the best I can do. Link to comment https://forums.phpfreaks.com/topic/160788-calling-javascript-function-from-php/#findComment-848589 Share on other sites More sharing options...
Styles2304 Posted June 3, 2009 Author Share Posted June 3, 2009 Your input tag is never closed. And I don't know how you want that function to trigger, so this is the best I can do. Yes it is, look closely. Right after "checked", I close the php tag and then close the input tag. I'm trying to trigger the function right there . . . that's what I'm asking for help with. The function is defined in a seperate file and loaded in the head but I don't know how to trigger it. Link to comment https://forums.phpfreaks.com/topic/160788-calling-javascript-function-from-php/#findComment-848596 Share on other sites More sharing options...
kickstart Posted June 3, 2009 Share Posted June 3, 2009 Yes it is, look closely. Right after "checked", I close the php tag and then close the input tag. I'm trying to trigger the function right there . . . that's what I'm asking for help with. The function is defined in a seperate file and loaded in the head but I don't know how to trigger it. Only if $Mil_Status == 'ETS' . Otherwise the closing tag is not output (it is inside the curley brackets for the if statement). All the best Keith Link to comment https://forums.phpfreaks.com/topic/160788-calling-javascript-function-from-php/#findComment-848606 Share on other sites More sharing options...
Mark Baker Posted June 3, 2009 Share Posted June 3, 2009 The function is defined in a seperate file and loaded in the head but I don't know how to trigger it. At the very bottom of your output, immediately before the closing </html> tag, do echo "<script language='javascript' type='text/javascript'>"; echo " toggleDisplay('show', 'Mil_FromTo', 'main');"; echo " toggleDisplay('hide', 'Mil_Serving', 'main');"; echo " toggleDisplay('hide', 'Mil_Discharge', 'main');"; echo "</script>"; or whatever variants you need Link to comment https://forums.phpfreaks.com/topic/160788-calling-javascript-function-from-php/#findComment-848666 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.