473,804 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Quesiton about two javascript functions, swtiching between them in ONCLICK

If I have two functions, and want to toggle back and forth between 1
and 2 from an onclick event.... how would I parse that? Thanks mucho

<script>

javascript function1() {

something1....

}

javascript function2() {

something2....

}

</script>

Apr 8 '06 #1
7 1414

<en*********@gm ail.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
If I have two functions, and want to toggle back and forth between 1
and 2 from an onclick event.... how would I parse that? Thanks mucho

<script>

javascript function1() { ****change for demo
function functionOne(){
something1....

}

javascript function2() { ***change for demo
function functionTwo(){
something2....

}

</script>

One way is to add another function that will call the first two alternately
and your button calls the new function instead of the other two.:...
var booly = true; //(not in a function)
function thirdFunction() {//**(Call this from the button)
if (booly){
functionOne();
}else{
functionTwo();
}
booly != booly; // **changes booly from true to false or vice-versa
}//*end of function
HTH

Apr 8 '06 #2
Having some problems with this, check it:

<script>
var booly = true; //(not in a function)
function openinput(){//**(Call this from the button)
if (booly){
null;
}else{
alert('hi2');
}
booly != booly; // **changes booly from true to false or
vice-versa
}//*end of function
</script>
<a href="#" onclick=openinp ut()>Click</a>
this should in theory show "hi2" after clicking the link twice?

Apr 8 '06 #3
wrote on 08 apr 2006 in comp.lang.javas cript:
Having some problems with this, check it:
Please quote what you are replying to. If you want to post a followup via
groups.google.c om, don't use the "Reply" link at the bottom of the
article. Click on "show options" at the top of the article, then click on
the "Reply" at the bottom of the article headers.
<http://www.safalra.com/special/googlegroupsrep ly/>

<script>
var booly = true; //(not in a function)
function openinput(){//**(Call this from the button)
if (booly){
null;
}else{
alert('hi2');
}
booly != booly; // **changes booly from true to false or
vice-versa
}//*end of function
</script>
<a href="#" onclick=openinp ut()>Click</a>
this should in theory show "hi2" after clicking the link twice?


No, because
1 you reload the page every time.
2 != is a comparison operator, not an assignment operator

Try:

<script type='text/javascript'>

var booly = false;

function myTest(){
if (booly)
alert('hi2');
booly = !booly;
return false;
}
</script>

<a href="#" onclick='return myTest()'>Click </a>


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 8 '06 #4
>
javascript function1() { ****change for demo
function functionOne(){

something1....

}

javascript function2() {

***change for demo
function functionTwo(){

something2....

}
>
</script>

One way is to add another function that will call the first two

alternately and your button calls the new function instead of the other two.:...
var booly = true; //(not in a function)
function thirdFunction() {//**(Call this from the button)
if (booly){
functionOne();
}else{
functionTwo();
}
booly != booly; // **changes booly from true to false or vice-versa }//*end of function
HTH


I don't believe I did that -
Change code from
booly != booly; //** incorrect comparison
to
booly = !booly; //**(correct assignment)
*** duh
Apr 8 '06 #5
JRS: In article <zG************ ******@bignews6 .bellsouth.net> , dated
Sat, 8 Apr 2006 02:27:54 remote, seen in news:comp.lang. javascript, Hal
Rosser <hm******@bells outh.net> posted :
One way is to add another function that will call the first two alternately
and your button calls the new function instead of the other two.:...
var booly = true; //(not in a function)
function thirdFunction() {//**(Call this from the button)
if (booly){
functionOne();
}else{
functionTwo();
}
booly != booly; // **changes booly from true to false or vice-versa
}//*end of function
HTH


Your code is unlikely to help anybody until you learn
(a) javascript,
(b) how to test code before posting it.

There is no assignment operator != (it is relational), and the line
containing it has no effect.

Consider, however

var B = true
...
(B = !B) ? F1() : F2()
or ((B = !B) ? F1 : F2) ()

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Apr 8 '06 #6
>
Your code is unlikely to help anybody until you learn
(a) javascript,
(b) how to test code before posting it.

There is no assignment operator != (it is relational), and the line
containing it has no effect. **** I caught it - but too late for your barb.
Consider, however

var B = true
...
(B = !B) ? F1() : F2()
or ((B = !B) ? F1 : F2) ()


Clever! Impresses me, but probably confuses the OP.
y'made me look at
http://developer.mozilla.org/en/docs...ical_Operators
for an explanation. thanky, thanky - keep it coming -
oh, and I will also persist due to your encouragement . :-)

Apr 8 '06 #7

<th*********@gm ail.com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.com.. .
Having some problems with this, check it:

<script>
var booly = true; //(not in a function)
function openinput(){//**(Call this from the button)
if (booly){
null;
}else{
alert('hi2');
}
booly != booly; // **changes booly from true to false or
vice-versa
}//*end of function
</script>
<a href="#" onclick=openinp ut()>Click</a>
this should in theory show "hi2" after clicking the link twice?

Sorry - change my code FROM "booly != booly TO "booly = !booly
I would have caught it if I tested it first -

Apr 9 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2081
by: Emre Sevinc | last post by:
Take a look at the following snippet: <html> <head> <script> function add(elementId) { var container = document.getElementById(elementId); for (var i = 0; i < 10; i++) { var elt = document.createElement('div'); elt.innerHTML = "" + i;
26
11084
by: wardy | last post by:
Hi all, looking for a little bit of help.....I'm currently in the process of trying to understand the impact of the 508 guidelines on a web site that I am involved with, and I have a question surrounding the use of Javascript. The site currently relies on Javascript for navigating from page to page - I cannot find anything in the 508 guidelines like the 6.3 WAI checkpoint for AA compliance: "Ensure that pages are usable when scripts,...
17
2689
by: yawnmoth | last post by:
http://www.frostjedi.com/terra/scripts/demo/this-alert.html http://www.frostjedi.com/terra/scripts/demo/this-alert2.html Why, when you click in the black box, do the alert boxes say different things? Shouldn't they say the same thing?
0
10599
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10346
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10347
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
10090
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...
1
7635
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
6863
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();...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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.