Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Cincinnati, Ohio
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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) 

  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    Cincinnati, Ohio
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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' "

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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; 07-11-2002 at 04:03 PM.

  • #5
    New Coder
    Join Date
    Jul 2002
    Location
    Cincinnati, Ohio
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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' "


  •  

    Posting Permissions

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