Jump to content

Recommended Posts

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.

Thanks
Raj
Link to comment
https://forums.phpfreaks.com/topic/3568-onclick-radio-button-problem/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.