Web Analytics Made Easy -
StatCounter Simple function w/ Name Help - CodingForum


No announcement yet.

Simple function w/ Name Help

  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple function w/ Name Help

    I want to create a function that will change the value of a text box. The hard part is passing the variables to the function and having it know that it's a variable, not the name of a textbox!
    For example, if I have a textbox named "box1" and I want to change the status to "Current", I could use
    How do I call that in the document.flightpurchase.???.value

    function changeStatus(name,status) {

    document.flightpurchase. + name + .value = status


  • #2
    I sort of solved my own question through trial-and-error:
    "document.flightpurchase[name].value = status

    However, I found another problem.
    I have a radio button that when clicked, changes the status to something. Then, when another radio button is checked, the status returns to another thing...

    So in a sense, I want to have text boxes that have a value written within it depending on whether or not the corresponding radio button is checked...

    So far the "onClick=changeStatus('box1','Current')" works, but I can't figure out how to change it back after it's not selected anymore


    none of these work...


    • #3
      function getRadioValue (radioObject) {
         var value =  null;
         for (var i=0; i<radioObject.length; i++) {
            if (radioObject[i].checked)
               value = radioObject[i].value;
         return value;
      // pass the whole form (sure, why not!) and the specific radio value to the function
      function fillTheBox (radioValue, yourform) {
         switch (radioValue)  {
            case "aValueYouGaveThe1stRadioButton" :
               yourform.textbox0.value = 'current';
               yourform.textbox1.value = "";
               yourform.textbox2.value = "";
                  ... and so on...
           case "the2ndradiobuttonvalue":
              yourform.textbox1.value = "current";
              yourform.textbox0.value = "";
              yourform.textbox2.value = "";
                 ... and so on...
                .... default values for the textboxes and radio object here.
         }// switch ()
      // here's code that calls the above. Put it in the appropriate place(s)
      var whatRadio = new String();  // or whatever type is appropriate
      whatRadio = getRadioValue (myradiobuttonname);
      fillthebox (whatRadio, theformname);
      Last edited by RadarBob; Jul 11, 2002, 04:20 PM.