Determine Selected Option

[Total: 0    Average: 0/5]

This will determine the unique value of selected option button from a control Array.

Head Code:

<SCRIPT LANGUAGE=javascript>
<!--
var ind=-2; // to 

function cmdselect_onclick() {
{
for(i=0;i<document.frmForm.optSelect.length;i++)
{
if (document.frmForm.optSelect[i].checked)
{
ind=document.frmForm.optSelect[i].value; 
alert(ind);
// This value can be sub mitted as a query string
// window.location.href="something.asp?ID="+ind 
// or canbe assigned to a hidden object and submit.
// document.frmForm.txtHidden.value=ind;
document.frmForm.submit;
return false //Exit the function once a selection is found
}
}
}
if (ind= -2)
window.alert("You must select a record to perform this operation");
}


//-->
</SCRIPT>

Body Code:

<FORM id=frmForm name=frmForm>
<INPUT TYPE="HIDDEN" NAME=txtHidden value="0">
<TABLE WIDTH=100 BORDER=1 CELLSPACING=1 CELLPADDING=1>
<Tr>
<Th>Select </Th> 
<Th>Country Code</Th>
<Th>Country </Th>
</Tr>
<TR>
<TD><INPUT type="radio" id=optSelect  name=optSelect value="C121"></TD>
<TD>C121</TD>
<TD>Canada</TD>
</TR>
<TR>
<TD><INPUT type="radio" id=optSelect  name=optSelect value="C223"></TD>
<TD>C223</TD>
<TD>India</TD>
</TR>
<TR>
<TD><INPUT type="radio" id=optSelect  name=optSelect value="C301"></TD>
<TD>C301</TD>
<TD>Sri Lanka</TD>
</TR>
<TR>
<TD><INPUT type="radio" id=optSelect  name=optSelect value="C4"></TD>
<TD>C4</TD>
<TD>United Arab Emirates</TD>
</TR>

</TABLE>
</FORM>
<INPUT type="button" value="Select It" id=Select name=cmdSelect LANGUAGE=javascript onclick="return cmdselect_onclick()">

Times Viewed: 3

Leave a Reply

Your email address will not be published. Required fields are marked *