37 users online (0 members and 37 guests)  


  Results 1 to 5 of 5

Related

  1. Radio Button in PHP    Forum: PHP Forum
    Replies: 3
  2. Replies: 3
  3. Replies: 1
  4. Replies: 4
  5. Replies: 1
  1. #1
    L1A1U1R1A's Avatar
    New User

    Status
    Offline
    Join Date
    May 2009
    Posts
    4

    Show value depending what radio button is selected

    Hi All,

    I am trying to create a type of questionnaire, where the 'value' of a radio button is displayed in the next field of a table.

    There are also going to be a few of these on each page, and the values of each one totalling up at the bottom...

    example code:

    <script type="text/javascript">
    function test() {
    document.getElementById("1").value="");
    }

    </script>

    <table>
    <tr><b>Potential Benefits</b>
    </tr>
    <tr>
    <td>Total value of the business benefits</td>
    <td> <input type="radio" id="1" name="val" value="1" onclick="test(value)" title="Total value of the business benefits">Less Than 50k<br>
    <input type="radio" id="1" name="val" value="2" onclick="test(value)" title="Total value of the business benefits">50 - 100k<br>
    <input type="radio" id="1" name="val" value="3" onclick="test(value)" title="Total value of the business benefits">More than 100k</td>
    <td>Severity <span id="1"></span>
    </td>
    </tr>
    </table>

  2. #2
    L1A1U1R1A's Avatar
    New User

    Status
    Offline
    Join Date
    May 2009
    Posts
    4

    Unhappy Re: Show value depending what radio button is selected

    Requirements have slightly changed since post,

    I now have a select option box, and i want to display the value of the selection on the next field of the table


    <form name="scope">
    <table border="1">
    <tr>
    <td><b>1</b></td>
    <td><b>Size & Scope</b></td>
    <td><b>Value</b></td>
    <td><b>Severity</b></td
    </tr>
    <tr>
    <td>1.1</td>
    <td>Current estimated total size of the development in mandays</td>
    <td><select name="size" id="size" onChange="getElement(this.value)">
    <option value="0">Choose Value</option>
    <option value="0">1 - 100</option>
    <option value="5">101 - 500</option>
    <option value="10">501 - 1000</option>
    <option value="20">1001 +</option></select></td>
    <td><span="size"/></span></td>
    </tr>
    </table>
    </form>

    I have tried (unsuccessfully) creating a javascript function for it, would really appreciate some help

    Thanks in advance

  3. #3
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: Show value depending what radio button is selected

    Hi there L1A1U1R1A,

    and a warm welcome to these forums.

    Try it like this...
    Code:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    
    <title></title>
    
    <style type="text/css">
    #scope,#scope th, #scope td {
        margin:auto;
        border-width:1px;
        border-style:solid;
        border-color:#b2b2b2 #000 #000 #b2b2b2;
     }
    #scope th, #scope td {
        border-color:#000 #b2b2b2 #b2b2b2 #000;
     }
    #choice {
        text-align:center;
        color:#600;
     }
    </style>
    
    <script type="text/javascript">
    if(window.addEventListener){
       window.addEventListener('load',displaySelection,false);
     }
    else { 
    if(window.attachEvent){
       window.attachEvent('onload',displaySelection);
      }
     }
    
    function displaySelection(){
    
       df=document.forms[0][0]
       df[0].selected='selected';
    
    df.onchange=function() {
       document.getElementById('choice').firstChild.nodeValue=this.value;
      }
     }
    </script>
    
    </head>
    <body>
    
    <form action="#">
    
    <table id="scope"><tr>
    <th>1</th>
    <th>Size &amp; Scope</th>
    <th>Value</th>
    <th>Severity</th>
    </tr><tr>
    <td>1.1</td>
    <td>Current estimated total size of the development in mandays</td>
    <td>
    <select>
     <option value="0" selected="selected">Choose Value</option>
     <option value="0">1 - 100</option>
     <option value="5">101 - 500</option>
     <option value="10">501 - 1000</option>
     <option value="20">1001 +</option>
    </select>
    </td>
    <td id="choice">0</td>
    </tr></table>
    
    </form>
    
    </body>
    </html>
    

  4. #4
    L1A1U1R1A's Avatar
    New User

    Status
    Offline
    Join Date
    May 2009
    Posts
    4

    Smile Re: Show value depending what radio button is selected

    Thank you, that is exactly what i meant.

    now i just have to work out how to create 15 pages with 10 questions per page, and then add up the totals, and post them to a results page lol

    Thanks again

  5. #5
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: Show value depending what radio button is selected

    No problem, you're very welcome.