473,385 Members | 1,587 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,385 software developers and data experts.

Why doesn't my javascript code work

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

✓ answered by Exequiel

you must have two functions, validate(myButton1) and validates(myButton2), you can also create the situition in one funtion but you need a condition to it.

7 1553
Dormilich
8,658 Expert Mod 8TB
How can I make both scripts work on the one page?
don’t use the same name for different functions.
Jul 16 '13 #2
"don’t use the same name for different functions". I don't think I have used the same name. Aren't "function validate(myButton1)" and "function validate(myButton2)" separate names or am I confused? How do you suggest I change it?
Jul 16 '13 #3
Rabbit
12,516 Expert Mod 8TB
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 256MB
you must have two functions, validate(myButton1) and validates(myButton2), you can also create the situition in one funtion but you need a condition to it.
Jul 17 '13 #5
hi,baby.u functions define error.two functions[validate(myButton1) and validates(myButton2)] name and arguments totality is equal.the function validates(myButton2) will replace to the validate(myButton1).
so, button1 and button2 invoking validate(myButton2).
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 256MB
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 Expert Mod 4TB
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
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...
53
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...
5
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,...
2
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...
3
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...
4
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...
5
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...
31
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...
4
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; ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.