raj_2006 Posted February 24, 2006 Share Posted February 24, 2006 Hi All...I am giving the code snippet here in javascript and html.The object of this code is to change/display the cell values upon selecting a radio button.[b]//code starts[/b]<script language="JavaScript" type="text/javascript"><!--function switchPayment(value) { for(i=0;i<100;i++) { var objM = document.getElementById("monthly"+i); var objA = document.getElementById("annuall"+i); if(objA) { if(value=="m") { if(i!=0) { objM.style.color = "#000000";//on text color objM.style.backgroundColor = "#EFEEB5";//on background color objA.style.color = "#FFFFFF";//off text color objA.style.backgroundColor = "#FFFFFF";//off background color } else { objM.style.backgroundColor = "#EFEEB5";//on background color objA.style.backgroundColor = "#DBDAA4";//off background color } } else { if(i!=0) { objM.style.backgroundColor = "#FFFFFF";//off background color objM.style.color = "#FFFFFF";//off text color objA.style.backgroundColor = "#EFEEB5";//on background color objA.style.color = "#000000";//on text color } else { objM.style.backgroundColor = "#DBDAA4";//on background color objA.style.backgroundColor = "#EFEEB5";//off background color } } } else { break; } } }[b]//HTML starts:[/b] <tr> <td id="monthly0" align="center" onClick="switchPayment('m');document.f.payment_freq[0].checked=true;" style="font-size:11px;background-color:#EFEEB5;">Monthly*<br> <input type="radio" name="payment_freq" value="M" onClick="switchPayment('m');" checked> </td> <td id="annuall0" align="center" onClick="switchPayment('a');document.f.payment_freq[1].checked=true;" style="font-size:11px;background-color:#EFEEB5;">Annual<br> <input type="radio" name="payment_freq" value="A" onClick="switchPayment('a');"> </td> </tr> <td id="monthly1" align="center" style="background-color:#EFEEB5;">$17.33</td><td id="annuall1" align="center" style="color:#FFFFFF;">$208.00</td></tr><tr><td id="monthly2" align="center" style="background-color:#EFEEB5;padding-top:15px;"> <td id="annuall2" align="center" style="color:#FFFFFF;padding-top:15px;"> </tr><tr> <td id="monthly3" align="center" style="background-color:#EFEEB5;"> <td id="annuall3" align="center" style="color:#FFFFFF;"> </tr>[b]//code ends[/b]Now what i want is to set the value of td id automatically.means here i am setting manually 1,2,3 besides monthly and annually.but these values has to be dynamic.because when there is 3 rows it is working fine.but after 1st 3 rows when the other rows are generating(due to while loop for mysql resultset) then the td id values are again setting as monthly1...monthly2...monthly3 as so on.But it should be like this monthly4...monthly5 and monthly6.Please dont mind for this long typing and hope you will understand by this......Please suggest what to do.ThanksRaj Quote Link to comment https://forums.phpfreaks.com/topic/3568-onclick-radio-button-problem/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.