Jump to content

Javascript If help


mowais

Recommended Posts

Hey Every One... :rolleyes: This is my first post in this forum.. I wants help in if condition....I have a two <div> in body and I want that if i click on a one <div> then program runs forward and if i click on a second <div> then program close and exit from the browser..How can i do this Plz Help me.... I'll be very thankful to you... :)

Link to comment
Share on other sites

I don't think you can do that, but you can create that effect with a hidden div. You'd create both divs and make one of them hidden. Then, a user could make it appear by toggling its visibility with the display proberty http://www.w3schools...yle_display.asp. PS Don't forget to follow your topic (see upper right).

Edited by niche
Link to comment
Share on other sites

you can bound callback function onclick event for each div. and in callback function do different jobs according to your needs.

  • Like 2
Link to comment
Share on other sites

A callback is a reference to a function that is given to another function so it can be called later on.

function a(callback) {	callback();}var b = function() {	alert("This is a callback");}// Make A call Ba(b );

  • Like 2
Link to comment
Share on other sites

Thnx all for reply .. But i don't understand because i am learning javascript and i want to do with only simple method.. I don't know how use call back and what is this... If there is any other Method plz share....

Link to comment
Share on other sites

Post some code that's as close to what need as possible (html, css and as much JS and possible) and we'll help you with the rest, but you need to post some code so we can see what you need..

Edited by niche
Link to comment
Share on other sites

Simple of My HTML Program that i want. HTML Code

<html><head></head><body><div class="question"><h1>What is Your Name?</h1></div><div class="trueans"><h3>Owais</h3></div><div class="falseans"><h3>Zeeshan</h3></div><div class="falseans"><h3>Samad</h3></div><div class="falseans"><h3>Shehrose</h3></div></body></html>

I want that if i click on 'Fine' then it asked second question of mine that i'll give otherwise close the program if anyone click on 'falseans'... And want to do this using javascript bcz i am learning it... Can i do this..

<script type="text/javascript">if(document.div.trueans == 'clicked'){return true;}else if(document.div.falseans == 'clicked'){window.close();}</script>

I know that javascript is wrong bcz i don't know how to return a process to the body again.. I hope u understand what i want..

Link to comment
Share on other sites

Why do you think you need javascript? Unless you already know JS, you probably should just use forms with php and mysql if there's data to save, There's nothing about your situation that says youshould use JS unless that's the way you want to do it. I have a feeling that you're going to want/need to save user input, in which case, JS would be a distraction right now especially if you're new to coding.

  • Like 1
Link to comment
Share on other sites

Why do you think you need javascript? Unless you already know JS, you probably should just use forms with php and mysql if there's data to save, There's nothing about your situation that says youshould use JS unless that's the way you want to do it. I have a feeling that you're going to want/need to save user input, in which case, JS would be a distraction right now especially if you're new to coding.
Thank. It means i can't do it right now. I should try this later..
Link to comment
Share on other sites

<html><head><script type="text/javascript">function onClickTrue() {	console.log('clicked true');	alert('clicked true');}function onClickFalse() {	window.close();}</script></head><body><div class="question"><h1>What is Your Name?</h1></div><div class="trueans" onclick='onClickTrue()'><h3>Owais</h3></div><div class="falseans" onclick='onClickFalse()'><h3>Zeeshan</h3></div><div class="falseans" onclick="onClickFalse()"><h3>Samad</h3></div><div class="falseans" onclick="onClickFalse()"><h3>Shehrose</h3></div></body></html>

Link to comment
Share on other sites

Yeh Well Said by Don E Also according to my understanding window.close() only works when a new window has been already opened. Is there any other option to close the browser if any one click on the wrong <div>. I means close tab and exit from the browser. If anyone knows plz post here.. Thanx all for reply and help me..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...