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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Disabling and clearing fields

    hi guys

    sorry this is probably simple but i search every where on CF and cant find it . I have a text field and a list field; when i click on a radio button i want the text and list fields to be disabled while at the same time the contents of the text field to be cleared and a value in the list to be selected.

    Thanks for any help!!

    vorl

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Remember, disabling a form field will NOT send the form field value to the server!!

    <input type="radio" onClick="doSomething()">

    Code:
    function doSomething()
       {
       document.formname.fieldname.disabled=true;
       document.formname.fieldname.value="";
       document.formname.selectName.selectedIndex=0; // pick the number of the option
       document.formname.selectName.options[document.formname.selectName.selectedIndex].selected = true; // needed to be cross-browser
       }

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts
    thanks mate just what i needed!!!

    one last thing is it possible add text to the list field without it having to be in the list??

    thanks

    vorl

    btw how do u know all this, are there ne tutorials u go 2?

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    A select element has options. The options have text. So, no, you can't put text in a select element without it being an option.

    You can, however, dynamically create any element you like and you can give options no value (so they don't really do much).
    Tell me more about why you want text in there and let's see what kid of solution works best for you.

    As to where I learned it, all over the place!
    I have a bunch of references and tutorials links here.
    http://www.ipwebdesign.net/useful_jsReferences.html

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts
    im creating a mailing list page. users have a choice of subscribing and unsubscribing.
    there are 3 fields- name, email and what they want to subscribe to. i have been able to make it so if they select the subscribe radio button all the text fields are blank and the list field goes to 'Please select'.
    when they click unsubscribe the name and list fields disable of which they are only allowed to enter their email.
    i just wanted to show from the disabled fields that they must enter their email address. i have been able to do this for the text field by having 'enter email address' in the disabled field. i could put the 'enter email address' in the list but when they are subscribing they can see this option which does not look good. thats why i wanted a way to just add text when unsubscribing but remove it when subscribing!!

    sorry for the long message!! hope u get what im saying??!!

    thanks vorl

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Why not just focus to the email field when the textbox and combobox are disabled?

    Code:
    document.formname.fieldname.focus();
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    You could just hide the elements they don't need to fill out.

    A very simple example:
    Code:
    <form name="f1">
    <input type="text" name="txt"><br>
    <input type="button" name="btn" onClick="document.f1.txt.style.display='none'" value="hide">
    </form>

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

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