Click to See Complete Forum and Search --> : passing dynamic radio button status
megan321
08-02-2003, 12:53 PM
Hi I have a set of radio buttons generated dynamically by CF all with the name isDisplayed. I need to update multiple records and can do that by making each radio button a unique name (isDisplayed#currentrow#) but if I do that then they each become a little group of one, and if the button is clicked, you cannot "unclick" it and also then more than one record can set to isdisplayed=1
with radio buttons it is either off or on, and when passed, only the fact that it is on is passed, not which record radio button is on.
I thought I would try javascript to check if the button is checked, and then try to pass the info to the action page. I can do the checking to see if it is checked, but then I do not know how to proceed. Can any of you Javascript gurus help? tia, megan
code
====================
<script language="JavaScript">
function change_status(){
//see if radio button is checked
for (i = 0; i < <cfoutput>#getArticles.RecordCount#</cfoutput>; i++){
if (document.Articles.isDisplayed[i].checked == true){---NOW WHAT---}
}//end
}//ends function
</script>
then
<input type="radio" name="isDisplayed" onClick="change_status()">
You can "unclick" with:
document.Articles.isDisplayed[i].checked="";
megan321
08-02-2003, 03:11 PM
Fang, thanks for replying
here is my problem
I am using coldfusion to dynamically create one radio button for each record. I want to use radio buttons because you can only select one in a group at a time.
If I make it so all of the record buttons are named isDisplayed, then I can uncheck just fine by clicking in any of the other radio buttons in that group, how ever when I am trying to pass to an action page all that gets passed is IF isDisplayed is on and NOT which record has isDisplayed on,
I can make it so each of the radio buttons generated by CF has a unique name using #currentrow#, so then each of theradio buttons is named, isDisplayed1, isDisplayed2, etc, and not isDisplayed so I guess I need an array or loop or something for each of these unique names so I can go
document.Articles.isDisplayed1[i].checked="";
document.Articles.isDisplayed2[i].checked=""; etc. for each of the separately named radio buttons but I don't know how in javascript, hope this is not too garbled, megan
How about storing the value of the selected radio button in a hidden input, whenever a radio button is selected it's value is stored in the hidden input.
<input type="radio" name="isDisplayed" value="MyContent" onClick="document.Articles.Store.value=this.value;">
<input type="hidden" name="Store" value="" />
You only need to pass/parse the vale of the hidden input and not the radio array.
I haven't tested this solution, but it should work. I know nothing about CF.
megan321
08-02-2003, 04:08 PM
Thank you! Thank you! Fang, that is just exactly what I needed:p
megan321
08-02-2003, 04:20 PM
Uh_OH fang, if a person clicks on on button and then changes their mind and clicks on another button, the value is still stored in the first "store" and then there are more than one records where isDisplayed is set to ! - is there a way to clear the previous "store" if anoter button is clicked? thanks SO much for your help - I really appreciate it ~ megan
megan321
08-02-2003, 05:59 PM
Ok - I am sure this is kind of primitive, but the code below works in IE but throws an error inolder netscape - can someone tell me what I am doing wrong? tis ~megan
<script language="JavaScript">
function change_status()
//see if radio button is checked
{for (i = 0; i < Articles.isDisplayed.length; i++)
{if (document.Articles.isDisplayed[i].checked == ""){document.Articles.Store1.value="0";
}
{if (document.Articles.isDisplayed[i].checked == ""){document.Articles.Store2.value="0";
}
{if (document.Articles.isDisplayed[i].checked == ""){document.Articles.Store3.value="0";
}
}//end
}//end
}//end
}//ends function
</script>
then
<input type="radio" name="isDisplayed" value="1" onClick="change_status();document.Articles.Store1.value=this.value;">
<input type="hidden" name="Store1" value="0" />
<input type="radio" name="isDisplayed" value="1" onClick="change_status();document.Articles.Store1.value=this.value;">
<input type="hidden" name="Store2" value="0" />
<input type="radio" name="isDisplayed" value="1" onClick="change_status();document.Articles.Store1.value=this.value;">
<input type="hidden" name="Store3" value="0" />
Khalid Ali
08-02-2003, 10:38 PM
in the for loop of you rjs you are missing doument before the form name
it should be like this
{for (i = 0; i < document.Articles.isDisplayed.length; i++)
megan321
08-02-2003, 10:46 PM
Khalid, Thank you!!! - I've been combing over this for a while now and being a beginner, just did not know what to look for
much appreciation, megan
Khalid Ali
08-02-2003, 11:01 PM
you are welcome..just for the future.....please do not multiple or cross post ..its not considered nice as well as its a load on the forums resources which can be avoided.
Thanks