473,770 Members | 5,299 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why doesn't my javascript code work

2 New Member
Can anyone help me with a JavaScript problem?
If you go to www.bidets4sale .com/test.htm you will see my webpage and if you right click on it you should be able to view the code.
I have two scripts but if you click on the top button (the button 1 script) it executes the button2 script.
How can I make both scripts work on the one page?
Jul 16 '13 #1
7 1560
Dormilich
8,658 Recognized Expert Moderator Expert
How can I make both scripts work on the one page?
don’t use the same name for different functions.
Jul 16 '13 #2
UKJohnny
2 New Member
"don’t use the same name for different functions". I don't think I have used the same name. Aren't "function validate(myButt on1)" and "function validate(myButt on2)" separate names or am I confused? How do you suggest I change it?
Jul 16 '13 #3
Rabbit
12,516 Recognized Expert Moderator MVP
That's two functions with the same function name. They just have different names for the input varibles. Input variables are not part of the function name.
Jul 16 '13 #4
Exequiel
288 Contributor
you must have two functions, validate(myButt on1) and validates(myBut ton2), you can also create the situition in one funtion but you need a condition to it.
Jul 17 '13 #5
ajunboys
2 New Member
hi,baby.u functions define error.two functions[validate(myButt on1) and validates(myBut ton2)] name and arguments totality is equal.the function validates(myBut ton2) will replace to the validate(myButt on1).
so, button1 and button2 invoking validate(myButt on2).
Expand|Select|Wrap|Line Numbers
  1.  
  2. <script language="javascript" type="text/javascript">
  3.            function validate(myButton1){
  4.         var  myButton1= document.getElementById('myButton1');
  5.         var  myDIV1= document.getElementById('DIV1');
  6.         setTimeout (function(DIV1){myButton1.style.display ='none';  },1);
  7.         setTimeout (function(DIV1){myDIV1.style.display ='inline'; },1);
  8.         }
  9. </script>
  10. <script language="javascript" type="text/javascript">
  11.            function validate(myButton2){
  12.         var  myButton2= document.getElementById('myButton2');
  13.         var  myDIV2= document.getElementById('DIV2');
  14.         setTimeout (function(DIV2){myButton2.style.display ='none';  },1);
  15.         setTimeout (function(DIV2){myDIV2.style.display ='inline'; },1);
  16.         }
  17. </script>
  18.  
Jul 17 '13 #6
Exequiel
288 Contributor
my suggestion is right and its working, he can create that two function,
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2.            function validate(myButton1){
  3.         var  myButton1= document.getElementById('myButton1');
  4.         var  myDIV1= document.getElementById('DIV1');
  5.         setTimeout (function(DIV1){myButton1.style.display ='none';  },1);
  6.         setTimeout (function(DIV1){myDIV1.style.display ='inline'; },1);
  7.         }
  8. </script>
  9. <script language="javascript" type="text/javascript">
  10.            function validates(myButton2){
  11.         var  myButton2= document.getElementById('myButton2');
  12.         var  myDIV2= document.getElementById('DIV2');
  13.         setTimeout (function(DIV2){myButton2.style.display ='none';  },1);
  14.         setTimeout (function(DIV2){myDIV2.style.display ='inline'; },1);
  15.         }
  16. </script>
,
he can also create his situition in only one function by determining if the button that been click is button1 or button2. . . , I suggest he can use Jquery for easy coding,
Jul 17 '13 #7
gits
5,390 Recognized Expert Moderator Expert
if nothing else of jQuery is used in the page - then i strongly recommend to NOT use it for such simple things. its a complete useless overhead to have a complete lib included without the need for it. and its not 'easier' with jQuery - at best a bit more convenient. there is not need to fire a rocket on a mosquito.
Jul 17 '13 #8

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

Similar topics

3
2794
by: Tommo | last post by:
Hello All, I am a still learning so be easy on me. I am trying to get some code to work that is using JS and Perl/CGI, I am using AS Perl and an Apache Server on XP as the webserver. Can anyone take a look at the code and tell me why I am getting Apache Server errors in the code below (Part A), when I modify the code as shown in part B the errors go but the JS does not run ?? Part A.
53
5745
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
5
2063
by: TrvlOrm | last post by:
HI There, I have been struggling with JavaScript code for days now, and this is my last resort! Please help... I am trying to create a JavaScript slide show with links for Next Slide, Previous Slide and Home Slide. Is it possible for you to view my page and tell me what I am doing wrong. I have looked at this page for hours and can't figure it out, I
2
1704
by: ms_mmswan | last post by:
I am trying to have multiple layers on a page that toggle on and off, it works on a htm file but when I use it as an asp file it doesnt show anything. This is the javascript code that is hindering my asp page: function MM_showHideLayers() { //v3.0 var i,p,v,obj,args=MM_showHideLayers.arguments; for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args))!=null) { v=args;
3
1623
by: kaston3 | last post by:
I use screen.width to check escreen resolution and then document.write to write different width tables accordingly. It all works OK with Mozilla Firefox, however it seems that in IExplorer it only works when I reload the page. I think it can be cache handling in IE. I tried putting the javascript code in an extrenal js.file. Then i tried calling that file with a random number (using time functions) eg. mycode.js?nn=secondss; but it...
4
1404
by: johnny15 | last post by:
I have copied from a site a javascript code for my web site to create a pop up. This works fine on older versions of browser but not the most recent. Whilst I have been searching for some new code to replace the old code I have also learnt that the javascript will not always work as it may not be enabled. Therefore does anyone have some code that I could copy that will work fine on all browser and if the javascript is not enabled. ...
5
2227
by: thatsMaBoy | last post by:
Hi, I am attempting to display a simple Javascript alert when a webpage loads. It works on some pages but not on others. For example, the following code does not produce an alert: Code in webpage1 (note, this is the only VB code in the ASPNET webpage, in other words, the rest is all HTML): Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
31
15385
by: ajos | last post by:
hi frnds, i have a form,which has 2 input text boxes, the values are entering the text boxes,when i leave the 2 text boxes blank and hit submit a java script gives the message that the 2 fields are blank.....the problem now is when i leave the text boxes blank the message appears...and when i click ok...then instead of showing me the page its giving me an exception--> type Exception report message description The server encountered an...
4
1663
by: supriyamk | last post by:
Hi, i am trying to copy files of a certain type into a different directory using perl, The copy function doesnt seem to work. my @dir_list; my $sub_dir; my $file_name1; my $file_name2; my @file_list_gel; my @file_list_res;
1
10001
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9867
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8880
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.