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 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 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
    changeStatus('box1','Current')
    How do I call that in the document.flightpurchase.???.value

    function changeStatus(name,status) {

    document.flightpurchase. + name + .value = status

    }

  • #2
    New Coder
    Join Date
    Jun 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    "onunClick=changeStatus('box1','Current')"
    "onChange=changeStatus('box1','Current')"

    none of these work...

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    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...
              break;
    
         case "the2ndradiobuttonvalue":
            yourform.textbox1.value = "current";
            yourform.textbox0.value = "";
            yourform.textbox2.value = "";
               ... and so on...
            break;
    
         default:
              .... default values for the textboxes and radio object here.
             break;
    
       }// 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; 07-11-2002 at 09:20 PM.


  •  

    Posting Permissions

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