Web Analytics Made Easy -
StatCounter setting up default datatype values for certain values in an input box - CodingForum

Announcement

Collapse
No announcement yet.

setting up default datatype values for certain values in an input box

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • setting up default datatype values for certain values in an input box

    Ok, Lets say I have 4 input boxes.
    The word either: "test", "prod", or "go" will be typed into the first input box.



    Input box1: "Go"

    Input box2: ______________

    Input box3: ______________

    Input box4: ______________


    Upon completion of this, in the final three text boxes, I want

    "a"
    "b"
    and "c"

    to be populated in the other three text boxes. For each word: "test, "proud", and "go" will be a set default that should appear in the following three boxes. With this type of algorithm...how would I script this??
    "Of all the saddest words every spoken or written by pen, there are no words sadder than 'what could've been' "

  • #2
    PHP Code:
    switch (document.theform.box1.value) {
       case 
    "go":
          
    document.theform.box2.value "a";
          
    document.theform.box3.value "b";
          
    document.theform.box4.value "c";
          break;

       case 
    "test":
          
    document.theform.box2.value "Larry";
          
    document.theform.box3.value "Moe";
          
    document.theform.box4.value "Curley";
          break;
       
       case 
    "proud":
          
    document.theform.box2.value "to be ";
          
    document.theform.box3.value "an ";
          
    document.theform.box4.value "American";
          break;

       default:   
    // don't ever say "I'll never hit this condition!!"
          
    alert ("oops, box1 has an unknown value: " document.theform.box1.value");
          break;
    } // switch (box1) 

    Comment


    • #3
      Thank you very much, heres what I've done with your snippit:
      -----------------------------------------------------------------------------------
      <html>
      <head>
      <link rel=stylesheet type=text/css href='template.css'>
      <title>Algorthm</title>
      <script language="javascript">

      switch (document.defaultext.textbox1.value) {
      case "go":
      document.defaultext.textbox2.value = "a";
      document.defaultext.textbox3.value = "b";
      document.defaultext.textbox4.value = "c";
      break;

      case "test":
      document.defaultext.textbox2.value = "Larry";
      document.defaultext.textbox3.value = "Moe";
      document.defaultext.textbox4.value = "Curley";
      break;

      case "prod":
      document.defaultext.textbox2.value = "to be ";
      document.defaultext.textbox3.value = "an ";
      document.defaultext.textbox4.value = "American";
      break;

      default:
      alert ("oops, box1 has an unknown value: " + document.defaultext.textbox1.value);
      break;
      }
      </script>


      </head>

      <body vspace=0 onLoad="document.defaultext.textbox1.onchange()">
      <table width=630 bgcolor=#999966 align=left>
      <tr height=20><td width="622">&nbsp;</td>
      </tr><tr>
      <td width="622">

      <!-- code goes here -->


      <table class=table align=center cellspacing=0 width=553>
      <tr>
      <td class=outTableTitle align=center colspan="2" width="535">
      <center>Algorithm</center></td>
      </tr>
      <form method="POST" name="defaultext" action="">
      <tr>
      <td class=outTableHead width="60"> Text1 </td>
      <td class=outTableText2 width="292">
      <input type="text" name="textbox1" size="40"></td>
      </tr><tr>
      <td class=outTableHead width="60"> Text2 </td>
      <td class=outTableText1 width="292">
      <input type="text" name="textbox2" size="40"></td>
      </tr><tr>
      <td class=outTableHead width="60"> Text3 </td>
      <td class=outTableText2 width="60">
      <input type="text" name="textbox3" size="40"></td>
      </tr><tr>
      <td class=outTableHead width="60"> Text4 </td>
      <td class=outTableText1 width="292">
      <input type="text" name="textbox4" size="40"></td>
      </tr>
      </form>
      </table>





      <!--code ends here -->


      </td>
      <tr>
      <td width="622">&nbsp;
      </td>
      </tr>
      <tr height=300>
      <td width="622">
      </td></tr></table>

      </body>
      </html>
      ----------------------------------------------------------------------------------

      I am still recieving an error...what am I doing wrong?
      "Of all the saddest words every spoken or written by pen, there are no words sadder than 'what could've been' "

      Comment


      • #4
        Karnac we're not. What's the error message (or symptoms)?

        1. you terminate your table just above the "code ends here" note. However you still use <tr> and <td> tags beyond that point. These need to be inside the table tags.

        2. I think you need to add an "onchange" event handler for your textbox1 object, thus:
        Code:
        <input type="text" name="textbox1" size="40" onchange="forceValues(this.value)">
        3. Make a function out of that code sample, thus:
        Code:
        function forceValues (textbox1Value)  {
           switch (texbox1Value) {
              case "go":
                     ... and so forth...
           }
        }
        Last edited by RadarBob; Jul 11, 2002, 10:03 AM.

        Comment


        • #5
          The script with just a few small adjustments works perfectly.



          THANK YOU SOOO MUCH FOR YOUR HELP!!!
          "Of all the saddest words every spoken or written by pen, there are no words sadder than 'what could've been' "

          Comment

          Working...
          X