SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    generating tag in textArea

    Code:
    code
    
    <form name="myForm">
    <table>
      <tr>
        <td>blue<input type='radio' name='radioButton' value='blue'></td>
        <td>yellow<input type='radio' name='radioButton' value='yellow'></td>
      </tr>
      <tr>
        <td>red<input type='radio' name='radioButton' value='red'></td>
        <td>green<input type='radio' name='radioButton' value='green'></td>
      </tr>
      <tr>
        <td>blue <input type='checkbox' name='checkbox' value='blue'></td>
        <td>yellow <input type='checkbox' name='checkbox' value='yellow'></td>
      </tr>
      <tr>
        <td>green <input type='checkbox' name='checkbox' value='green'></td>
        <td>red <input type='checkbox' name='checkbox' value='red'></td>
      </tr>
    </table>
    <textArea name="myTextArea">myText</textArea>
    </form>
    I have a textArea like the above.

    If a user clicks a radio button or check box which value is "blue" after he blocks the area of "myText"
    The following tag is generated in the textArea.
    "<color='blue'>myText</color>"


    If a user clicks a radio button or check box which value is "yellow" after he blocks the area of "myText"
    The following tag is generated in the textArea.
    "<color='yellow'>myText</color>"


    If a user clicks a radio button or check box which value is "red" after he blocks the area of "myText"
    The following tag is generated in the textArea.
    "<color='red'>myText</color>"


    If a user clicks a radio button or check box which value is "green" after he blocks the area of "myText"
    The following tag is generated in the textArea.
    "<color='green'>myText</color>"

    If it can make the generating tag I want, either radio button or check box will be O.K.

    Can I make it with your help?

  2. #2
    SitePoint Addict bronze trophy AllanP's Avatar
    Join Date
    Sep 2010
    Location
    Australia
    Posts
    298
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This will do it for you.

    <title>Radio Button Fills Text Area</title>
    <script type="text/javascript">
    <!--
    function process()
    { var i;
    var formLength=document.myForm.radioButton.length;
    // check which button was checked
    for( i=0;i<formLength;i++)
    { if(document.myForm.radioButton[i].checked==true)
    {
    var stringTxt="\"<color='"+document.myForm.radioButton[i].value+"'>myText</color>\"";
    document.myForm.myTextArea.value=stringTxt;
    return true;
    // ---------------
    }
    // if nothing selected
    document.myForm.myTextArea.value="No Selection";
    }
    }
    // ------------------
    //-->
    </script>
    <style type="text/css">
    <!--
    #TT1 td { text-align:right; }
    -->
    </style>
    </head>

    <body>

    <form name="myForm">
    <table id="TT1" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="200">
    <tr>
    <td>blue</td>
    <td><input type="radio" name="radioButton" value="blue"></td>
    <td>yellow</td>
    <td><input type="radio" name="radioButton" value="yellow"></td>
    </tr>
    <tr>
    <td>red</td>
    <td><input type="radio" name="radioButton" value="red"></td>
    <td>green</td>
    <td><input type="radio" name="radioButton" value="green"></td>
    </tr>
    </table>
    <p><input type="button" value="Get Code" onclick="process()"></p>
    <p><textarea name="myTextArea" rows="1" cols="35">myText</textarea> </p>
    </form>

    </body>

    </html>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •