I am using a PHP script, but say I had two radio buttons, right?
How could I actually execute code, such as (main intention | display a messagebox) upon selection of one or the other?
Say I had a radio button named RadioButton1, Once checked/selected, a message box would appear saying RadioButton1 Selected?
Is this possible through PHP alone? Or do I need to integrate an html page which posts to the PHP page?
Use Javascript for client side interaction like that. The code below listens for the
onchangeevent and shows analert().jsFiddle Demo
The first 3 lines are the radio buttons HTML. After that we have the
<script>tag which denotes Javascript code. The Javascript is adding some code to theonloadevent, which simply means: execute this code when the page is loaded. Next we get all of the radio button elements into an array calledradios– for that we usegetElementsByName()passing the radio button group name which ismyradio. Next we loop through each radio button in the array and assign anonchangehandler, which means: execute this code when each radio button is changed. Within that, we check if the radio button ischeckedand if it is, we show the alert, showing the radio button’s value which will beRadioButton1,RadioButton2,RadioButton3.