javascript form and function problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gameguru
    New Member
    • Aug 2010
    • 2

    javascript form and function problem

    The problem is rather sinple: I can't figure out how to make the script work:
    Code:
    <head><script language="JavaScript">
     var dynamic_code_index;
     var dynamic_code_index="Click a button to display the code in the textbox";
      function SetTextbox (num) {
     dynamic_code_index=num;
     }
     dynamic_code_view.dynamic_code_box.value=dynamic_code_index; 
     // Makes a usable variable which is applied to the textbox
     </script></head>
    <body>
    <!--creates the form and stuff!-->
      <form type="dynamic_code_view" action="" method="GET">The code will be displayed into the box: <BR>
      <input type="text" name="dynamic_code_box" value="This website is not working properly"><P>
      <input type="button" name="button1" value="example" onclick=SetTextbox('hello')>
      </form>
      </body>
    I'm trying to make the script so that there's a textbox(I will make it multi-lined later) which displays a variable that is changed when a button is clicked. There will be more than 1 button. Why doesn't this code work, and, please can someone post a working version? And I labelled the form things with dynamic because it's a really cool word, that's all =).
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    Run the specific HTML Page in Firefox and use Error Console to figure out your problem.

    Even though there is few issue i am pointing out:
    why you need to define dynamic_code_in dex globally twice?(check line 2,3)

    On line 7 you used another global statement
    dynamic_code_vi ew.dynamic_code _box.value=dyna mic_code_index;
    Which has no meaning. Cause it is not defined what is dynamic_code_vi ew. there is no attribute name type for form tag. to learn how to access form element suing javascript please follow the link

    Comment

    • omerbutt
      Contributor
      • Nov 2006
      • 638

      #3
      here you go ,
      Code:
      <head><script type="text/javascript">
        var dynamic_code_index="Click a button to display the code in the textbox";
         function SetTextbox (num) {
        	dynamic_code_index=num;
      	document.forms['dynamic_code_view'].dynamic_code_box.value=dynamic_code_index; 
        }
        
        // Makes a usable variable which is applied to the textbox
        </script></head>
       <body>
       <!--creates the form and stuff!-->
         <form name="dynamic_code_view" id="dynamic_code_view" action="" method="GET">The code will be displayed into the box:
      	   <input type="text" name="dynamic_code_box" value="This website is not working properly">
      	   <input type="button" name="button1" value="example" onclick='SetTextbox("hello")' />
         </form>
         </body>

      Comment

      • gameguru
        New Member
        • Aug 2010
        • 2

        #4
        thanks

        Thanks for the help you guys, and the 2nd code worked perfectly so I'm set!

        Comment

        Working...