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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Generate personal button with java (textual adventure building)

    Hi all,

    I've got two questions :

    I use this script, send "word" for receive "answer" :

    Code:
    <form name="form1" method="post">
      <textarea name="fname1" value=""></textarea><br>
    <input type="submit" value="send"></form> 
     
    <script type="text/javascript">
    	function validateForm() {
    	var x = document.forms["form1"]["fname1"].value;
    	if (x === "word" ) {
    		document.forms["form1"].innerHTML +=("answer");   
    	} return false; }
    		document.forms["form1"].onsubmit = validateForm;
    </script>
    -> But i'd like receive this button (with his script) instead of "answer" :

    Code:
    <div id="1">
    <input type="button" onClick="return toggleMe('2')" value="to 2"></div>
    <div id="2" style="display: none;">
    2
    <input type="button" onClick="return toggleMe('3')" value="to 3"></div>					  
    <div id="3" style="display: none;">
    3
    <input type="button" onClick="return toggleMe('4')" value="to 4"></div>  
    <div id="4" style="display: none;">
    4 etc
    </div>
    
    //in <head>
    
    <script type="text/javascript">
    function toggleMe(a){
      var next=document.getElementById(a);
      var b=new String();
      b= a-1;
      var prev=document.getElementById(b);
      if(!next)return true;
      if(next.style.display=="none"){
        next.style.display="block"
        prev.style.display="none"
        window.scrollTo(0,0);
      } else {
        next.style.display="none"
      }
      return true;
      }
    </script>
    -> Second question, is it also possible to define the button that will appear depending on what you will write in the text area ?

    Thanks for your help.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Be aware that Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia!

    An id may not start with a number. There must be at least one letter at the beginning.

    A form should be assigned an id, not a name (which is now obsolete).
    Last edited by Philip M; 08-12-2013 at 04:33 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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