I am facing problems while writing a program that has 3 radio buttons, each radio button, when checked, should display a small form on the part of the same webpage. I am using AJAX and PHP. My question is, how do I write the function to display the corresponding form if a radio button is checked? Please note that I am new to AJAX/PHP.
<input type="radio"
name="RadioGroup1"
value="radio"
id="RadioGroup1_0"
onclick="showView()" />
Personally? I would hold them each in a div and conditionally display them. Unless you have really good cause, there is no reason you can't load this up front (and it introduces another point of failure to use AJAX to actually load the div's here).
function hideElements()
{
// using jQuery, I would probably loop and use a class selector here.
// but this is an example.
document.getElementById("tag1").style.display = "none";
document.getElementById("tag2").style.display = "none";
document.getElementById("tag3").style.display = "none";
}
As your listener on the radio buttons (probably through something like $("#tag1, #tag2, #tag3).click, if you're using jQuery, onclick or addEventListener if you're doing this bare-bones)
function showElement( tag ) //tag == "tag1" through "tag3"
{
hideElements();
document.getElementById("tag1").style.display = "inline"
}
If AJAX is a must (back-end logic is a requirement for whether the form is shown), I would still load them up front and only conditionally display the forms based off of the response from the back-end.