JavaScript - Windows.open - Pop Up And Return Some Value
Hi Guys,
I want to develop a javascript code which will open a pop up window and a JSP page in it. That JSP page will load a 'Select' list which user will select a value from and I want that value to be returned to my parent form (window). I remember implementing the same long time back (almost 5years now) ...can anyway help remind me how did I do it...or how can I do it? Regards, -- SJunejo Similar TutorialsI am getting double Alert prompts for a single form: The alert pops up the first time, then when I click OK, the same one pops open again. I think my code should do the alert once when it hits "else window.alert(sameWarning) and the stop when it reaches "return false()"; but it seems return false() is causing the alert twice. Maybe because I have two forms on one page; yet, they have two separate function names ("signinForm()" and "saveSignUp()")and call two separate forms (forms[0] and forms[1])? I think my code is correct, but I can't figure it out at this point. Any help would be appreciated. Thanks in advance! Code: <script type="text/javascript"> //FIRST FUNCTION FOR FORMS[0] function signinForm(){ // var sameWarning = "The required fields were not submitted for the following error(s). \n \n"; var warningLogin = "The following field(s) require an entry: \n \n"; var sameWarning = warningLogin; var userName = document.forms[0].userName.value; var pswd = document.forms[0].pswd.value; if(userName == ""){ sameWarning += " - First Name \n"; } if(pswd == ""){ sameWarning += " - Password \n"; } if (warningLogin == sameWarning){ return true; } else { window.alert(sameWarning); } return false; } //SECOND FUNCTION CALL FOR FORMS[1] function saveSignUp(){ // var warning = "The required fields were not submitted for the following error(s). \n \n"; var warning = "The following field(s) require an entry: \n \n"; var same = warning; var firstName = document.forms[1].firstName.value; var lastName = document.forms[1].lastName.value; var email = document.forms[1].email.value; var phone = document.forms[1].phoneNumber.value; if(firstName == ""){ //firstName.style.backgroundColor="red"; warning += " - First Name \n"; } if(lastName == ""){ warning += " - Last Name \n"; } if(email == ""){ warning += " - Email \n"; } if(phone == ""){ warning += " - Work Phone \n"; } if(phone < 5 ){ warning += " - Must be a numberssss \n"; } if (warning == same){ return true; } else { alert(warning); } return false; } </script> HTML Code: <h1>Login</h1> <form method="post" onsubmit="return signinForm();" action="" > <input type="text" placeholder="Username/Email" name="userName"> <input type="password" placeholder="Password" name="pswd" id="pswd"> <input type="submit" onclick="signinForm();" value="Sign In"> </form> <h1>Sign Up!</h1> <form method="post" onsubmit="return saveSignUp()" action="" > <input type="text" placeholder="First Name" name="firstName"> <input type="text" placeholder="Last Name" name="lastName"> <input type="text" placeholder="Email" name="email"> <input type="text" placeholder="Phone Number" name="phoneNumber"> <input type="submit" onclick="saveSignUp();" class="button wide" value="Request an Account"> </form> *UPDATE Fixed! After I removed the onclick in the button, the double alerts went away. Apparently, I was I was firing off two events (calling the javascript twice) with both the onsubmit and the onclick. Just wondering: 1. Is "onsubmit" a special event handler just for button "type=submit" vs onlclick can be used for any element? 2. Is there a preference among developers to use onclick vs. onsubmit? 3. Is there an order of precedence for method calls over submit calls (the onclick goes first, then it automatically fires the submit call to the function too)? This is a pet peeve of mine and I'm still looking for a solution. If I have designated a specific size dimension for a popup window to open with (as one must, otherwise why even use a pop-up window?) then it should be obvious that the window needs to open up at 100% (normal) magnification, otherwise the contents of the window will not be displayed properly. It seems to me current browsers are struggling with this problem, as Firefox, Safari, and Opera all handle it differently. For example, Firefox applies magnification settings defined by the user to dimensions of the pop-up window but not to the contents (an odd solution!); Opera retains the correct dimensions but applies magnification to the contents. Only Safari handles it correctly: even if you have applied magnification to a web page it will still open pop-up windows at default 100% magnification and honor the dimensions specified in the HTML code by the page designer. Thanks for any help you can provide. I don't understand the logic of Break, Return False, Return True. It was never really covered in our college class, and I see everyone using it. I got an A in the class, if that 'proves' that I really tried to apply myself. NOTE: I understand what the function is doing. I just don't understand WHEN to use break, return false or return true if the the translator can determine the conditional statements. PHP Code: function submitForm(){ var ageSelected = false; for (var i=0; i<5; ++1){ if (document.forms[0].ageGroup[i].checked == true) { ageSelected = true; break; } } if (ageSelected == false){ window.alert("You must select your age group"); return false; } else return false; } if the the translator can determine the conditional statements, why not write it like this: PHP Code: function submitForm(){ var ageSelected = false; for (var i=0; i<5; ++1){ if (document.forms[0].ageGroup[i].checked == true) { ageSelected = true; break; // what's the point for the 'break'? Won't the rest of the code be ignored since it passed the first condition? } } if (ageSelected == false){ window.alert("You must select your age group"); return false; } // why not leave the last else out? is it just a 'safety' catch, in case something other than true or false is inputted? else return false; // what's the point? } Questions: Why use return true, if the translator knows it's ture? Why use "return false" if the translator knows it's false and the alert window has already gone up? why not use "break" to stop the code? Why use the "return false" at the end "else" statement? Hi room, Hey, I opened up the source code for this page in google chrome and since i'm learning javascript, i wanted see if i could "read" it and figure out what was going on. I'm am having the hardest time understanding "return false" and "return true". Could someone step me through this via interpreting this code (in bold typeface): Code: var DefaultValue = 'Search'; function clearSearch() { if (document.searchForm.q.value == DefaultValue) { document.searchForm.q.value = ''; } } function validateSearchHeader() { if ( document.searchForm.q.value == '' || document.searchForm.q.value.toLocaleLowerCase() == DefaultValue.toLocaleLowerCase() ) { alert('Please enter at least one keyword in the Search box.'); document.searchForm.q.focus(); return false; } return true; } Thanks! Hi, I want to restrict opening my popup window if it is already opened. For simple scenario, it is quite possible to do but in my case -- 1) When parent page is opening popup window, it is getting refreshed (required from client for some reason). 2) Once submit button is clicked from popup window, again parent page is getting refreshed (again its a requirement from client side). With these 2 conditions, I lost my saved value from variable and hence new popup is keep coming when the action is same. Currently I am using below code to open popup [CODE] function OpenWindow() { if(winPop && !winPop.closed) { alert("Popup is already open"); } else { winPop = window.open('MyPopupPage.aspx'); } } [CODE] Please help me to get rid of this problem. Thanks in advance. - Bhasker I do write some php, but have not much idea about JavaScript. I use window.open to open 10 pages simultaneously. I prefer to open them with a time delay from each other to put less load on the target server. This is my code with no delay. (I played around with setTimeout but can't get it to work.) PHP Code: <a href='http://www.".$new[9]."' onclick="window.open('http://www.".$new[0]."/'); window.open('http://www.".$new[1]."/'); window.open('http://www.".$new[2]."/'); window.open('http://www.".$new[3]."/'); window.open('http://www.".$new[4]."/'); window.open('http://www.".$new[5]."/'); window.open('http://www.".$new[6]."/'); window.open('http://www.".$new[7]."/'); window.open('http://www.".$new[8]."/')\" target='new300/'>Open 10</a> Hello! I'm trying to make a website that from one link, opens multiple windows. It is for a design project (I'm still at uni). So far I have mustered just the one window. Here is the website: http://popmeup.org/ The idea is that you get bombarded with lots of nice quotes. I don't know my arse from my Javascript - but has anyone got any advice? Hi. I don't know if anyone here has downloaded the dev edition of windows 8 yet (it was released last night 5:00p, est) I am trying to get jquery to work, but it just wont... I tried simple stuff, but I was hoping someone here knew how. Thanks This is my first time writing any JavaScript, so I am not very familiar with the language. I want to make a window be kept at the back, under all other windows. From what I understand, the method to do this would be window.blur(), but I cannot seem to get it to work. Have I misunderstood the functionality, or am I implementing it wrong? The part of the code I have that currently deals with this (or at least tries) is as follows: Code: <BODY onclick="window.blur()" > <img src="imageurl" id="image"></img> </BODY> I've tried a few other events to trigger this (onmouseover, setInterval, etc.) but no way I've tried has worked. So, is blur() the right method to do this? have I done something wrong in the implementation? Any help and guidance is appreciated. Backstory (if it should matter for some reason) : I found a webpage ( here and here ) that generates an image of the Earth as seen from space at a given time and I wanted to place that image, updated on a regular basis, as my desktop image. I looked around for a way to do it, but as far as I could find, there was no way to do it easily in Windows XP. Thus, I am now using Samurize (a program for overlaying graphics etc. at your desktop) to create a browser window that loads a html file that periodically updates the image. While this window cannot be moved and has no borders, it can be selected and if it is selected, the image is brought to the front, overlapping any other windows. I wish to make it such that this cannot happen; I have tried configuring Samurize as well as asking for help on their forums, but no luck so far. I thought I did everything right but pop-up windows aren't working... Code: <td> <a href="javascript:popUp('http://www.retrocitysunglasses.com/popupfreeshipping.html')"><img src="http://www.retrocitysunglasses.com/website_graphics/header_free_shipping.jpg" alt="Free Shipping"></a> </td> Code can be found on this page (very first section after body opens): http://retrocitysunglasses.com/ You can see the website here with all the code to make it easier for you to diagnose what is happening: Code: http://www.fdfdaa.com/desktop/desktop.html When you go to the start menu and select anything on the left side, you will see that windows open 100% of the screen by default. I did that by adding maximized:true but that doesn't appear to be working for the icons on the desktop itself. If you click on one of those 4 icons on the desktop though, it isn't opening at 100% for some reason. You can see my classes file here as well: Code: http://www.fdfdaa.com/desktop/classes.js Any help will be greatly appreciated. Thank you for your time! -Removed due to solution found-
Hi, I'm trying to make a pop up window that should work such as the window the pops up when you press "View all friends" on one of your friends' profiles on Facebook. Is this possible? Thank you! Hi, I need javascript to sort as windows sorts its file. For eg: When the files name contains special characters, number and alphabets(#@!$%.doc, test1.doc,test2.doc, 1.doc) javascript sorts alphabets first and then special characters, but windows sorts special characters first and then alphabets in ascending. I want javascript to sort my array as windows. Kindly help me out in this case. Thanks, Deva. I have searched high and low to find this script. Not having much luck at all. What i want to do is, when someone clicks a link the image pops up on screen in its own nice window smack down in the middle of the screen over top of the website. I want it to look neat tho, best example i can find is @ curse.com http://wow.curse.com/downloads/wow-a...st-helper.aspx If you click that link and scroll down to the screen shot section and click on one of the images you can see how nice and professional it looks. How can i accomplish this? Thanks so much in advance~ Hi everyone, I'm trying to capture the order in which the windows I've opened using window.open are layered on top of each other. For example, if I open three windows, starting with the first on the bottom and the third on top, but I then focus on the second window, bringing it to the top, is there a way to capture the new window order (2 on top, then 3, then 1)? I know that window.top can give me the first one, but from there, without closing it, is there a way to tell what the next one underneath it is? Thanks in advance, Katherine This seems like it would be so simple and I have absolutely no idea. I have one page with no frames, and two links on it. The second page has an iframe on it. Both links on page 1 point to page 2 (which houses the iframe), but based on which link is clicked will determine what that iframe will display. Basically I need to figure out a way to target the iframe on page 2 after executing a window.open statement. Much like how google images creates a frame at the top after you click on one of the images from the search results. I've attached two simple files to better explain what I'm trying to do. FrameSet.zip I'd appreciate the help, I'm losing my mind. In the past I write the jave script to popup windows in the browser for tell our visitor about news & event but now most of browser will block popup by default. Someone can show me an example about the professional popup with out the block.Thank you
Ok I need to open a popup in a second monitor. The browser will be open in the first monitor and the popup needs to open in the second monitor (we'll say it's to the left for now). I have tried a few Javascript methods. I don't have PHP avaliable to me in this case but I do have the ability to use JSP and will shortly have JQuery. Here is what I have tried so far: Code: <script type="text/javascript"> function popup(url, winName, xOffset, yOffset) { var x = (window.screenX || window.screenLeft || 0) + (xOffset || 0); var y = (window.screenY || window.screenTop || 0) + (yOffset || 0); return window.open(url, winName, 'top=' +y+ ',left=' +x); } </script> <form> <input type="button" onClick="popup('http://www.google.com', 'myWin', -600, 100)" value="Show Customer"/> </form> and Code: <script type="text/javascript"> function popup() { window.open( "http://igatedev.kirbyrisk.com/DualMonitorTest/product.jsp?part=545347", "myWindow", "status=0, fullscreen=0, resizable=1" ) } </script> Any help is much appreciated. Also I was wondering if there was a way to have the popup close with the original window, or with a button click from the first. Hi - I have an ASP.Net 4.0 solution that runs fine on a Windows 2008 server. However, I've just been given a new Windows 7 64-bit machine to use as my development machine and I'm having a problem with one of my aspx pages. This page has some javascript on it, which runs fine, but then it gets to the following code: Code: <script type="text/javascript"> //<![CDATA[ var theForm = document.forms['aspnetForm']; if (!theForm) { theForm = document.aspnetForm; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } //]]> </script> This not code that I've written; it's code that's generated client-side that I see as I'm debugging my app in Visual Studio 2010 (trying to figure out what the $^#$ is going on). At any rate, once this code completes, the app does nothing. The debugger should take me to some server-side code, but it doesn't. It just sits there. The result is that the page doesn't do what it's supposed to do (no inserts to databases, no success messages, no nothing). As I said, this problem is restricted to my W7 64-bit machine; it runs fine on W2008. Other pages with javascript in the same solution work fine on my W7 machine. I found a post (http://dopostback.net/index.php/net-...anel-problems/) that discusses a similar issue within an UpdatePanel, but I'm not using UpdatePanel. My page does have hidden controls on it, but so do other pages that work just fine. Does anyone know what could be causing this? Thanks! |