简体   繁体   中英

Generating Radio Button Result Depending On TextArea Value

A few days ago I did not manage to generate a result from my radio button, I managed to solve that problem now. My other problem is how do I generate ONLY few set of the radio button depending on TextArea value changes;

For Example in this code

    <script language="javascript" type="text/javascript">

function generatetest() {

codeOne = document.docContainer.text1.value;
codeTwo = document.docContainer.number2.value;

function firstType(){

var codeFour = 0;

for( i = 0; i < document.docContainer.radio4.length; i++ )
    {
    if( document.docContainer.radio4[i].checked == true )
    codeFour = document.docContainer.radio4[i].value;
    }

var codeTen = 0;

    for( i = 0; i < document.docContainer.radio10.length; i++ )
    {
    if( document.docContainer.radio10[i].checked == true )
    codeTen = document.docContainer.radio10[i].value;
    }

document.docContainer.textarea12.value = codeOne + codeTwo + codeFour + codeTen;
}

function secondType(){

var codeSix = 0;

for( i = 0; i < document.docContainer.radio6.length; i++ )
    {
    if( document.docContainer.radio6[i].checked == true )
    codeFour = document.docContainer.radio6[i].value;
    }

var codeEleven = 0;

    for( i = 0; i < document.docContainer.radio11.length; i++ )
    {
    if( document.docContainer.radio11[i].checked == true )
    codeTen = document.docContainer.radio11[i].value;
    }

document.docContainer.textarea12.value = codeOne + codeTwo + codeSix + codeEleven
}

if (document.docContainer.number2.value="1")
{
firstType();
}
else if (document.docContainer.number2.value="2")
{
secondType();
}


}
</script>

The code is working, problem is, even though I insert the value on textarea "number2" as "2", the code still generate firstType() result

Am Im using wrong if-statement or what and how do I go around about this?

Your code could be more fun to read, but Putting quotes around your numbers is causing javascript to treat them like text. Is this what you want to be doing?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM