We help IT Professionals succeed at work.
Get Started
Troubleshooting Question

How do I assign the value of a radio button to a php variable

Tanabe Saori
Tanabe Saori asked
Last Modified: 2021-01-20
I have two divs where either one is hidden and the other one isn't.
these are generated by PHP and I have to set the initial state of the divs based on a radio button set named 'worksheets'.
<input type="radio" name="worksheets" value="alpha" id="worksheets_0" checked="checked">
<input type="radio" name="worksheets" value="nums" id="worksheets_1">
I've already worked out grabbing which radio button is selected, using:
so, I attempted to echo this, but ran into syntax trouble with the mixed single and double quotes in the javascript.
a$ = "
a$= "<script>$("input[type='radio'][name='worksheets']:checked").val();</script>";

So then I tried to put that into a function and call the function, but was still stuck.
a$ = "<script type='text/javascript'>worksetter();</script>";
I also tried
a$ = "?> <script type='text/javascript'>worksetter();</script> ?>";
which isn't working either. Lastly, I tried
a$ = echo "<script type='text/javascript'>worksetter();</script>";
of course, that doesn't work either. I tried a couple other things, which didn't work either.

What am I missing?
Watch Question
Sr. System Analyst
This problem has been solved!
Unlock 2 Answers and 16 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE