SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: form control

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form control

    Hello,

    I came across some code which shows and hides form fields and uses a Div so a few lines of the form slides up or down and depending on whether or not the form fields are visible or hidden from the Check Box selection

    here is the link http://www.tek-tips.com/faqs.cfm?fid=4585

    I want to do this but instead of using a check box, I want to use a Graphic image button hyperlinked to the Javascript function

    I am not a javascript programmer, but I figured that I can achieve the desired using cookies.

    Here is my effort, I do not think the cookies are working properly, I just want them to store a state and then that state gets updated next time around


    my code, can anyone assist me, I am not a javascript coder just basic basic knowledge.


    HTML Code:
    <head>
    <script language="JavaScript">
      function showhidefield()
      {
        if (document.frm.chkbox.checked)
        {
          document.getElementById("hideablearea").style.visibility = "visible";
        }
        else
        {
          document.getElementById("hideablearea").style.visibility = "hidden";
        }
      }
    </script>
    
    
    
    
    
    
    <script language="JavaScript">
      function showhidefield1()
      {
        if (document.frm.chkbox.checked)
        {
          document.getElementById("hideablearea").style.visibility = "visible";
        }
        else
        {
          document.getElementById("hideablearea").style.visibility = "hidden";
        }
      }
    </script>
    
    
    </head>
    
    
    
    <body>
    
    
    
    
    <form name='frm' action='nextpage.asp'>
    
    
    <a href="" OnClick="showhidefield()"><img src="familybutt.jpg"></a>
    
       Reveal the message below
      <br>
      <div id='hideablearea'  style='display:none'>
    	<br>
            hello world message is displayed here
    	
      </div>
    
    
    
    
    
    </form>
    
    
    <script language="JavaScript">
      function showhidefield()
      {
         
    
    
        if (document.cookie == "A")
        {
          document.getElementById("hideablearea").style.display = "none";
          document.cookie = "name1=A";
    
        }
        else
        {
          document.getElementById("hideablearea").style.display = "block";
                document.cookie = "name1=b";	
        }
      }
    </script>
    
    
    
    
    
    
    <body>

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No need of cookies. You can use any global variable.
    HTML Code:
    <script language="JavaScript">
      function showhidefield()
      {
        if (document.isShown)
        {
          document.getElementById("hideablearea").style.display = "none";
          document.isShown = 0;
        }
        else
        {
          document.getElementById("hideablearea").style.display = "block";
         document.isShown = 1;	
        }
      }
    </script>

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi prasanthmj

    Thank you ever so much for your reply, what you shared makes total sense,

    Have I missed something else. I want when the hyperlinked button is clicked for the message to stay on the screen (inside the Div), and then when I click the link again the message disappears , just like how it was working with the check box example I based this on.

    I think there is something else I need to do in the main body of the code, can you please help me with that,

    Much appreciated


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
  •