$15 for some working javascript

Discussion in 'JavaScript' started by explorer, Jan 11, 2007.

  1. #1
    I'll paypal $15 to the first person who posts clean, working javascript to do the following:

    1. The code will work on an .html page.

    [​IMG]


    2. Column 4 in each row will be a text box. Users will be able to enter their own number into this text box OR have the text box filled in for them by selecting one of the radio buttons from the same row. For example, in Row 1, the user will be able to enter their own number in Column 4 or put value a, value b or value c into the textbox by clicking on the appropriate radio button. (a,b and c are numbers.) The user will also be allowed to change their mind and select or enter new values at any stage.

    3. After the user has placed a number in Column 4 for each of Rows 1,2,3 and 4, they can press the Add button. This will add up the numbers in each text box in Column 4 to produce a result. (Users will be allowed not to place a value in any row. In this case, the value in column 4 of that row should be counted as zero when the addition is carried out.)


    Thanks.
     
    explorer, Jan 11, 2007 IP
  2. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Please copy and paste this code in your favorite text editor and save it with some filename .html and open in web browser and test it...

    cheers let me know you need anything else. ... i am online on yahoo and msn please contact me would like to chat with you ..



    <html>
      <head>
      </head>
      <body>
      <script language="javascript">
          function getTotal()      
          {
            var v1 = parseInt(document.getElementById("txt1").value)
            var v2 = parseInt(document.getElementById("txt2").value)
            var v3 = parseInt(document.getElementById("txt3").value)
            var v4 = parseInt(document.getElementById("txt4").value)
            var stp = 0
            if (isNaN(v1))
            {
              stp = 1
              document.getElementById("txt1").value = "";
              document.getElementById("txt1").focus()
              alert("Not a valid entry!")
              return
            }
            if (isNaN(v2))
            {
              stp = 1
              document.getElementById("txt2").value = "";
              document.getElementById("txt2").focus()
              alert("Not a valid entry!")
              return
            }
            if (isNaN(v3))
            {
              stp = 1
              document.getElementById("txt3").value = "";
              document.getElementById("txt3").focus()
              alert("Not a valid entry!")
              return
            }
            if (isNaN(v4))
            {
              stp = 1
              document.getElementById("txt4").value = "";
              document.getElementById("txt4").focus()
              alert("Not a valid entry!")
              return
            }
            if(stp == 0)
            {
              total = v1+v2+v3+v4;        
              document.getElementById("total").value = total;
            }
          }        
      </script>
      <table border="1">
            <tr>
                <td>
                  &nbsp;
                </td>
                <td>
                    Col1
                </td> 
                <td>
                    Col2
                </td> 
                <td>
                    Col3
                </td>
                <td>
                    Col4
                </td>
            </tr>
            <tr>
                <td>
                  row1
                </td>
                <td>
                    <input type="radio" name="row1" id="row1"  value="1" onclick="document.getElementById('txt1').value = this.value" >
                 </td> 
                <td>
                    <input type="radio" name="row1" id="row1"  value="2" onclick="document.getElementById('txt1').value = this.value">
                </td> 
                <td>
                    <input type="radio" name="row1" id="row1"  value="3" onclick="document.getElementById('txt1').value = this.value">
                </td>
                <td>
                    <input type="text" name="txt1" id="txt1"  value="" size="4" >
                </td>
            </tr>
            <tr>
                <td>
                  row2
                </td>
                <td>
                    <input type="radio" name="row2" id="row2"  value="5" onclick="document.getElementById('txt2').value = this.value">
                </td> 
                <td>
                    <input type="radio" name="row2" id="row2"  value="6" onclick="document.getElementById('txt2').value = this.value">
                </td> 
                <td>
                    <input type="radio" name="row2" id="row2"  value="7" onclick="document.getElementById('txt2').value = this.value">
                </td>
                <td>
                    <input type="text" name="txt2" id="txt2"  value="" size="4" >
                </td>
            </tr>
            <tr>
                <td>
                  row3
                </td>
                <td>
                    <input type="radio" name="row3" id="row3"  value="9" onclick="document.getElementById('txt3').value = this.value">
                </td> 
                <td>
                    <input type="radio" name="row3" id="row3"  value="10" onclick="document.getElementById('txt3').value = this.value">
                </td> 
                <td>
                    <input type="radio" name="row3" id="row3"  value="11" onclick="document.getElementById('txt3').value = this.value">
                </td>
                <td>
                    <input type="text" name="txt3" id="txt3"  value="" size="4">
                </td>
            </tr>
            </tr>
            <tr>
                <td>
                  row4
                </td>
                <td>
                    <input type="radio" name="row4" id="row4"  value="13" onclick="document.getElementById('txt4').value = this.value">
                </td> 
                <td>
                    <input type="radio" name="row4" id="row4"  value="14" onclick="document.getElementById('txt4').value = this.value">
                </td> 
                <td>
                    <input type="radio" name="row5" id="row4"  value="15" onclick="document.getElementById('txt4').value = this.value" >
                </td>
                <td>
                     <input type="text" name="txt4" id="txt4"  value="" size="4">
                </td>
            </tr>    
            <tr>
                <td colspan="4" align="right" >
                  
                </td>            
                <td>
                  <input type="button" value="Add" name="btnadd" onclick="getTotal()" >
                </td>
            </tr>        
            <tr>
                <td colspan="4" align="right" >
                  Result/Total:
                </td>            
                <td>
                    <input type="text" name="total" id="total"  value="" size="4" readonly >
                </td>
            </tr>
      <table> 
      </body>
    </html>
    Code (markup):
     
    rays, Jan 11, 2007 IP
  3. explorer

    explorer Well-Known Member

    Messages:
    463
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Hi rays, thanks for the code.

    When I try to run it, I get a script error that says line 47, char 11 object doesn't support this property or method.
     
    explorer, Jan 11, 2007 IP
  4. explorer

    explorer Well-Known Member

    Messages:
    463
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    110
    #4
    I was just thinking that, in the interests of fairness, I won't accept any other code for a little while until rays has had a chance to amend his code. Thanks. :)
     
    explorer, Jan 11, 2007 IP
  5. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #5
    <html>
      <head>
      </head>
      <body>
      <script language="javascript">
          function getTotal()      
          {
            var v1 = parseInt(document.getElementById("txt1").value)
            var v2 = parseInt(document.getElementById("txt2").value)
            var v3 = parseInt(document.getElementById("txt3").value)
            var v4 = parseInt(document.getElementById("txt4").value)
            var stp = 0
            if (isNaN(v1))
            {
              stp = 1
              document.getElementById("txt1").value = "";
              document.getElementById("txt1").focus()
              alert("Not a valid entry!")
              return
            }
            if (isNaN(v2))
            {
              stp = 1
              document.getElementById("txt2").value = "";
              document.getElementById("txt2").focus()
              alert("Not a valid entry!")
              return
            }
            if (isNaN(v3))
            {
              stp = 1
              document.getElementById("txt3").value = "";
              document.getElementById("txt3").focus()
              alert("Not a valid entry!")
              return
            }
            if (isNaN(v4))
            {
              stp = 1
              document.getElementById("txt4").value = "";
              document.getElementById("txt4").focus()
              alert("Not a valid entry!")
              return
            }
            if(stp == 0)
            {
              var total = v1+v2+v3+v4;        
              document.getElementById("total").value = total;
            }
          }        
      </script>
      <table border="1">
            <tr>
                <td>
                  &nbsp;
                </td>
                <td>
                    Col1
                </td> 
                <td>
                    Col2
                </td> 
                <td>
                    Col3
                </td>
                <td>
                    Col4
                </td>
            </tr>
            <tr>
                <td>
                  row1
                </td>
                <td>
                    <input type="radio" name="row1" id="row1"  value="1" onclick="document.getElementById('txt1').value = this.value" >
                 </td> 
                <td>
                    <input type="radio" name="row1" id="row1"  value="2" onclick="document.getElementById('txt1').value = this.value">
                </td> 
                <td>
                    <input type="radio" name="row1" id="row1"  value="3" onclick="document.getElementById('txt1').value = this.value">
                </td>
                <td>
                    <input type="text" name="txt1" id="txt1"  value="" size="4" >
                </td>
            </tr>
            <tr>
                <td>
                  row2
                </td>
                <td>
                    <input type="radio" name="row2" id="row2"  value="5" onclick="document.getElementById('txt2').value = this.value">
                </td> 
                <td>
                    <input type="radio" name="row2" id="row2"  value="6" onclick="document.getElementById('txt2').value = this.value">
                </td> 
                <td>
                    <input type="radio" name="row2" id="row2"  value="7" onclick="document.getElementById('txt2').value = this.value">
                </td>
                <td>
                    <input type="text" name="txt2" id="txt2"  value="" size="4" >
                </td>
            </tr>
            <tr>
                <td>
                  row3
                </td>
                <td>
                    <input type="radio" name="row3" id="row3"  value="9" onclick="document.getElementById('txt3').value = this.value">
                </td> 
                <td>
                    <input type="radio" name="row3" id="row3"  value="10" onclick="document.getElementById('txt3').value = this.value">
                </td> 
                <td>
                    <input type="radio" name="row3" id="row3"  value="11" onclick="document.getElementById('txt3').value = this.value">
                </td>
                <td>
                    <input type="text" name="txt3" id="txt3"  value="" size="4">
                </td>
            </tr>
            </tr>
            <tr>
                <td>
                  row4
                </td>
                <td>
                    <input type="radio" name="row4" id="row4"  value="13" onclick="document.getElementById('txt4').value = this.value">
                </td> 
                <td>
                    <input type="radio" name="row4" id="row4"  value="14" onclick="document.getElementById('txt4').value = this.value">
                </td> 
                <td>
                    <input type="radio" name="row5" id="row4"  value="15" onclick="document.getElementById('txt4').value = this.value" >
                </td>
                <td>
                     <input type="text" name="txt4" id="txt4"  value="" size="4">
                </td>
            </tr>    
            <tr>
                <td colspan="4" align="right" >
                  
                </td>            
                <td>
                  <input type="button" value="Add" name="btnadd" onclick="getTotal()" >
                </td>
            </tr>        
            <tr>
                <td colspan="4" align="right" >
                  Result/Total:
                </td>            
                <td>
                    <input type="text" name="total" id="total"  value="" size="4" readonly >
                </td>
            </tr>
      <table> 
      </body>
    </html>
    HTML:
     
    rays, Jan 11, 2007 IP
  6. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #6
    rays, Jan 11, 2007 IP
  7. explorer

    explorer Well-Known Member

    Messages:
    463
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    110
    #7
    Hi rays, working perfectly in FF, Opera, IE 7. Unfortunately, it's not working in IE6 and a lot of my visitors are still using that browser. Clicking the radio buttons fills in the text boxes with the numbers but the script won't add them. I get an "error on page" message at the bottom left.
     
    explorer, Jan 11, 2007 IP
  8. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #8
    can you please post me exact error
     
    rays, Jan 11, 2007 IP
  9. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #9
    i tested it on IE on my friend laptop its working like a champ [​IMG]
     
    rays, Jan 11, 2007 IP
  10. explorer

    explorer Well-Known Member

    Messages:
    463
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    110
    #10
    I don't know the exact error, unfortunately.

    The only message I get is the little yellow triangle in the bottom left of the IE6 window with text beside it saying "Error On Page".

    In fact, looking again at IE7, there is the same trouble there - the numbers won't add up and there's an "Error On Page" message.
     
    explorer, Jan 11, 2007 IP
  11. explorer

    explorer Well-Known Member

    Messages:
    463
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    110
    #11
    My apologies rays,

    The script is working. Please PM me your paypal address and I'll send the money. Thank you very much. :)
     
    explorer, Jan 11, 2007 IP