SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Form Field Inaccessable, "Greyed Out" until checkbox clicked

    Hello,

    I've seen this done before, but I'm not sure how.

    I need to have a textbox of a form field greyed out, inaccessable, blocked, until a checkbox is checked(or if it's already activated, it becomes inaccessable when turned off.

    Important!

    Thanks.

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should give you the idea

    Code:
    <script language="javascript1.2">
    	<!--
    		function disable_enable()
    		{
    			//if the surfer is using IE 4 or above
    			if (document.all)
    			{
    				if (document.test1.test2.disabled==true)
    				{
    					document.test1.test2.disabled=false
    				}
    				else
    				{
    					document.test1.test2.disabled=true
    				}
    			}
    		}
    		function changeState(formElement,bool)
    		{
    			dom="document.bob."
    			dis=".disabled="
    			eval(dom+formElement+dis+bool)
    		}
    	-->
    	</script>
    That controls the element. replace test1 with your formname. and replace test2 with your specific elementname

    Code:
    <form name="test1">
    	<input type="text" id="test2" name="form2" value="">
    	<input type="checkbox" onclick="disable_enable()" value="">
    </form>
    I hope that helps. And if not try this link

    http://www.javascriptkit.com/javatutors/deform3.shtml
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  3. #3
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. PHP does this too, right?
    I have so many instances and ifthens for greying out I may have to use that instead

    But thanks!

  4. #4
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by geiger
    Thanks. PHP does this too, right?
    Nope. Greying out forms is purely a client side thing. You can use PHP to generate the javascript that tells the browser to grey out a form though.

  5. #5
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm. That's what I thought initially, but that's not what my scripter said! I guess we'll wait and see. I actually heard it from another person, as well.

  6. #6
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no need for javascript, as javascript is a way of referencing
    PHP Code:
    <input type="button" value="blanked out" disabled="true" /> 
    so you can use php to determine this

    like
    PHP Code:
    <?

    $enabled
    =true;

    echo 
    "<input type=\"button\" value=\"blanked out\" disabled=\"$enabled\" />"

    ?>
    so even if javascript is disabled this method will work, as long as you have access to a server side language on your host

  7. #7
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah. I wonder how my scripter is going to do it, because I need fields to me specifically locked and unlocked based on choices made on the same page- no refresh.

    That sounds client-side to me but

  8. #8
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    btw you can just add "disabled>" at the end of of your tag and it works- I'm just wondering about disabling/enabling on the same page without a refresh.

  9. #9
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    course you can, its only html, but the correct way in xhtml would be to do it like above

    PHP Code:
    <input type="button" value="blanked out" disabled="true" /> 

  10. #10
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah. I know. I've gotten that far.

    I mean being able to enable and disable a field based on your actions on the same page. With PHP. No refresh.

  11. #11
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes its possible, it can be done with remote scripting or the xml dom

    you can see it in action here

    http://andrew-j.port5.com/requests/requesting.html

    PHP Code:

    methods   
    'GET';
    locatedAT 'serving.php';
    bool      'false';

    var 
    objHTTP = new ActiveXObject("Microsoft.XMLHTTP")
    objHTTP.Open(methodslocatedATbool)
    objHTTP.Send()

    //use innerHTML to retreive

    document.all['theForm'].innerHTMLobjHTTP.responseText 
    make something like a div and it will be replaced by the properties returned from the file being retreived.

    so just echo what ever data.

    heres the remote scripting method

    http://ashleyit.com/rs/rslite/

    populating a dropdown menu from a database

    http://ashleyit.com/rs/jsrs/select/php/select.php

  12. #12
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wouldn't it also work on NS6?

  13. #13
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really am not sure, just test the rs script though it should, work


Bookmarks

Posting Permissions

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