www.webdeveloper.com
Results 1 to 2 of 2

Thread: Show Hidden Submit Button IF input matches value

  1. #1
    Join Date
    Jul 2007
    Posts
    76

    Show Hidden Submit Button IF input matches value

    Hi there,

    I hope someone can help, I am stuck with my code: http://jsfiddle.net/old_blueyes/JELCK/

    Currently my code is largely working the way in envisage apart from one part.

    At the moment I have if you click the Try It button I have random quotes appear in textboxes now what quotes appear depends on a hidden value which i have set.

    Now what I wish for is that if one of those textboxes displays a certain quote i.e. if MEDIUM is displayed then it shows a hidden Submit button so I can process the form.

    I've had a couple of attempts myself but haven't really got anywhere.

    My latest attempt is at the bottom of code within the link posted above.

    Cheers

  2. #2
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,681
    Code:
    <!DOCTYPE html>
    <html>
    <body>
    
    <h2>Java Test</h2>
    
    <button onclick="myFunction(); update();">Try it</button>
    
    <input type="hidden" id="age" value="18"/>
    
    <textarea id="agebox" style="width:150px;" readonly="readonly"></textarea>
    
    <textarea id="prcbox" style="width:150px;" readonly="readonly" onchange="submitChange()"></textarea>
    
    <input type="submit" id="submit" style="display: none;" />
    
    
    <script>
    function myFunction() {
      var age,voteable;
      age=document.getElementById("age").value;
      voteable=(age<18)?"Too young":"Old enough";
      document.getElementById("agebox").value=voteable;
    }
    
    function update() {
      var msg = 'Invalid entry';
      var age=document.getElementById("age").value;
      if ((age > 0) && (age <= 10)) { msg = 'EASY'; }
      if ((age > 10) && (age <= 20)) { msg = 'MEDIUM'; }
      if ((age > 20) && (age <= 30)) { msg = 'HARD'; }
      document.getElementById("prcbox").value=msg;
      submitChange();
    }
    
    
    function submitChange()
    {
     var inputOne = document.getElementById("prcbox");
     var inputSubmit = document.getElementById("submit");
         if(inputOne.value == "MEDIUM")
         {
              inputSubmit.style.display = "block";
         }
         else
         {
              inputSubmit.style.display = "none";
         }
    }
    
    </script>
    
    
    </body>
    </html>
    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/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles