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 to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing variable..

    I'm somewhat new to javascript, but not new to programming. I program in php and vb. What I'm trying to do and can't figure out is this. I'm calling a function in the onclick handler of a checkbox that I need to do two things (since I can't call two functions in one handler). When the function runs it checks to current count of checked checkboxes.

    Now out beside the checkbox I have a disabled textbox that I'm trying to programmitcally enable when the checkbox is turned on, but I have several of these on one page so it's not as easy as just turning it on (so it seems anyway). So at the bottom of this function I'm trying to figure out how to pass the substr varable into a obj.form.textfield.disabled = false; string. my textfields are textfield1-xx and they match the checkbox they are next to, so if someone checks box number 4 it's named box4 and the textbox is textfield4, so by doing obj.name.substr(3) I get the number, and I can echo that all day long, I just can't put that into the obj.form call. How can I do that?

    Thanks!! Jon

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,536
    Thanks
    3
    Thanked 513 Times in 500 Posts
    there are a number of 'disable' scripts on
    http://www.vicsjavascripts.org.uk/Fo...Compendium.htm

    keyword search 'disable'
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't need a whole new script (unless this isn't possible), I just need to know how to pass a variable to the above referenced type of call. To elaborate a little more I'll provide the function and associated call so hopefully it's clear what I'm trying to do.

    [code]
    <SCRIPT LANGUAGE="JavaScript">

    function countChoices(obj) {
    max = 2; // max. number allowed at a time

    box1 = obj.form.box1.checked;
    box2 = obj.form.box2.checked;
    box3 = obj.form.box3.checked;
    box4 = obj.form.box4.checked;
    box5 = obj.form.box5.checked;

    count = (box1 ? 1 : 0) + (box2 ? 1 : 0) + (box3 ? 1 : 0) + (box4 ? 1 : 0) + (box5 ? 1 : 0);

    if (count > max) {
    alert("Oops! You can only choose up to " + max + " choices! \nUncheck an option if you want to pick another.");
    obj.checked = false;
    }

    alert("obj.form.textfield" + obj.name.substr(3) + ".disabled = false;")
    }
    // End -->
    </script>
    [code]

    The call I make in the checkbox is:

    <input type=checkbox name=box1 onClick="countChoices(this)">

    Next to it is this textfield:

    <input disabled="true" name="textfield1" type="text" size="40">

    What I want to happen is someone to check the box, within that function the textfield is passed to obj.form.textfield as above and enable the textbox. Is it possible like I'm trying to do it. I know it's possible in other languages, so I'd guess that it's possible in javascript I'm just not sure how.


  •  

    Posting Permissions

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