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

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 1396

<en*********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.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=openinput()>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.javascript:
Having some problems with this, check it:
Please quote what you are replying to. If you want to post a followup via
groups.google.com, 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/googlegroupsreply/>

<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=openinput()>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******@bellsouth.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.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.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*********@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.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=openinput()>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
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 =...
26
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...
17
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...
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: 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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...
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...

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.