473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

javascript form and function problem

The problem is rather sinple: I can't figure out how to make the script work:
Expand|Select|Wrap|Line Numbers
  1. <head><script language="JavaScript">
  2.  var dynamic_code_index;
  3.  var dynamic_code_index="Click a button to display the code in the textbox";
  4.   function SetTextbox (num) {
  5.  dynamic_code_index=num;
  6.  }
  7.  dynamic_code_view.dynamic_code_box.value=dynamic_code_index; 
  8.  // Makes a usable variable which is applied to the textbox
  9.  </script></head>
  10. <body>
  11. <!--creates the form and stuff!-->
  12.   <form type="dynamic_code_view" action="" method="GET">The code will be displayed into the box: <BR>
  13.   <input type="text" name="dynamic_code_box" value="This website is not working properly"><P>
  14.   <input type="button" name="button1" value="example" onclick=SetTextbox('hello')>
  15.   </form>
  16.   </body>
  17.  
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 =).
Aug 11 '10 #1

✓ answered by omerbutt

here you go ,
Expand|Select|Wrap|Line Numbers
  1. <head><script type="text/javascript">
  2.   var dynamic_code_index="Click a button to display the code in the textbox";
  3.    function SetTextbox (num) {
  4.       dynamic_code_index=num;
  5.     document.forms['dynamic_code_view'].dynamic_code_box.value=dynamic_code_index; 
  6.   }
  7.  
  8.   // Makes a usable variable which is applied to the textbox
  9.   </script></head>
  10.  <body>
  11.  <!--creates the form and stuff!-->
  12.    <form name="dynamic_code_view" id="dynamic_code_view" action="" method="GET">The code will be displayed into the box:
  13.        <input type="text" name="dynamic_code_box" value="This website is not working properly">
  14.        <input type="button" name="button1" value="example" onclick='SetTextbox("hello")' />
  15.    </form>
  16.    </body>
  17.  

3 1443
johny10151981
1,059 1GB
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_index globally twice?(check line 2,3)

On line 7 you used another global statement
dynamic_code_view.dynamic_code_box.value=dynamic_c ode_index;
Which has no meaning. Cause it is not defined what is dynamic_code_view. there is no attribute name type for form tag. to learn how to access form element suing javascript please follow the link
Aug 11 '10 #2
omerbutt
638 512MB
here you go ,
Expand|Select|Wrap|Line Numbers
  1. <head><script type="text/javascript">
  2.   var dynamic_code_index="Click a button to display the code in the textbox";
  3.    function SetTextbox (num) {
  4.       dynamic_code_index=num;
  5.     document.forms['dynamic_code_view'].dynamic_code_box.value=dynamic_code_index; 
  6.   }
  7.  
  8.   // Makes a usable variable which is applied to the textbox
  9.   </script></head>
  10.  <body>
  11.  <!--creates the form and stuff!-->
  12.    <form name="dynamic_code_view" id="dynamic_code_view" action="" method="GET">The code will be displayed into the box:
  13.        <input type="text" name="dynamic_code_box" value="This website is not working properly">
  14.        <input type="button" name="button1" value="example" onclick='SetTextbox("hello")' />
  15.    </form>
  16.    </body>
  17.  
Aug 11 '10 #3
Thanks for the help you guys, and the 2nd code worked perfectly so I'm set!
Aug 11 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bill S. | last post by:
Hi, I am just starting to work with ASP, so bear that in mind... I have an ASP page that displays records from a table, and allows you to add, update and delete. There is a form with one...
7
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
10
by: iam247 | last post by:
Hi In my prototype asp page (with no javascript and no password validation, I have a registration form with the following action: <form name="form" method="post" action="RegDetails.asp"> ...
2
by: Myk Quayce | last post by:
I have a small .aspx page that uses old style forms with client-side JavaScript validation. Everything works fine until I try to upate the database with some new information. I must be doing...
1
by: John | last post by:
Hi I have two forms on my page. Both use javascript to validate input before submission. Problem is that first form does the validation fine but the second form gets submitted without any...
0
by: Boricua | last post by:
I'm using ASP.NET 2.0 I got an imagebutton at the end of my form as a submit button. When the user clicks it the button becomes disabled and continues with the postback. This is what I got, ib...
0
by: baburk | last post by:
Hi, Because of having ajax ScriptManager EnablePartialRendering = "true" the java script doesn't call public void FocusControl(Control ctrl) { System.Text.StringBuilder sb...
3
chathura86
by: chathura86 | last post by:
for (i = 0; i <= 30; i++) { var obj = 'date_' + i; document.getElementById(obj).onmouseover = function (event) { alert(i) }; } date_1, date_2, date_3, ........., date_30 are...
3
by: PrabodhanP | last post by:
I hv following javascript form validation code works in IE but not in Mozilla-Firefox ...please suggest <script type="text/javascript"> function IsNumeric(strString) // check for valid...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.