473,800 Members | 2,406 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with form in window popup

263 Contributor
Hi all.

I have this JavaScript function that copy the value ( selected in a select open in a window popup), in the hidden main form field.

I need this changes:

1) If the popup window is not requested by the user, the hidden main form field take value = 0;
2) If the window is open to force the user to make a choice within the select.

Can you help me?
Thanks

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2. <!--
  3.  
  4. function setValue(selObj)
  5. {
  6.  
  7.   if (!window.opener || selObj.selectedIndex <= 0) return;
  8.  
  9.   var vl = "";
  10.   var opts = selObj.options;
  11.  
  12.   for ( n = 0 ; n < opts.length ; n++ )
  13.     {
  14.       if (opts[n].selected)
  15.         {
  16.           if (vl.length > 0) vl += ", ";
  17.           vl += opts[n].value;
  18.         }
  19.     }
  20.  
  21.   window.opener.document.Qform.NASCOSTO.value = selObj.value;
  22.  
  23.  
  24.   window.close();
  25.  
  26. }
  27.  
  28. // -->
  29. </script>
Aug 28 '09 #1
9 1965
gits
5,390 Recognized Expert Moderator Expert
so just to understand that correctly:

1. when the user doesn't open the window the field should be set to 0? that is the default value of the field?

2. when he/she once opens the window ... then a selection has to be made and the window couldn't be closed without a selection?
Aug 28 '09 #2
viki1967
263 Contributor
1. when the user doesn't open the window the field should be set to 0? that is the default value of the field?
The default value of the field is NULL;

2. when he/she once opens the window ... then a selection has to be made and the window couldn't be closed without a selection?
Exactly...

Try this:
http://www.avia-it.com/public/js/gits.htm

thanks...
Aug 28 '09 #3
gits
5,390 Recognized Expert Moderator Expert
for the first issue you might just set the default to 0 or map it in your code because you know that the value NULL translates to 0 in your case.

for the second issue you might use the onbeforeunload handler of the window to react properly to the user's actions ... have a look here for the usage ...

kind regards
Aug 29 '09 #4
viki1967
263 Contributor
for the first issue it's ok...

for the second issue I don't understand the user's actions in my case... sorry...

If the window is open to force the user to make a choice within the select...

Can you tell me how resolve the problem ?

Regards
Viki
Aug 29 '09 #5
gits
5,390 Recognized Expert Moderator Expert
just use the onbeforeunload-event to validate whether the user has selected something or not ... and then do whatever you want in case the user didn't select something ... give a warning, avoid to close the window or whatever ... you could even use a custom dhtml-window so that you don't need to fiddle with different windows and close buttons etc.
Aug 29 '09 #6
viki1967
263 Contributor
OK, but can you tell me how I modify my code?
Aug 29 '09 #7
gits
5,390 Recognized Expert Moderator Expert
come on :) ... you should know that in this forum you should show some efforts to solve it first ... so try to implement the onbeforunload handler first ... the link shows you how you should use it ...

kind regards
Aug 29 '09 #8
viki1967
263 Contributor
OK, I understand...

I write this code... working but I'am not sure it is a conform solution to the problem ...

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <title>Popup</title>
  5.  
  6. <script language="javascript" type="text/javascript"> 
  7. <!--
  8.  
  9.  
  10. function conferma(){
  11.  
  12.   if(document.Qform.ELEMENTO.value.length <= 0)
  13.   {
  14.      alert("Compila tutti i campi");
  15.   }
  16.   else
  17.   {
  18.      document.Qform.submit();
  19.   }
  20.  }
  21.  
  22.  
  23. function setValue(selObj)
  24.  
  25.   if (!window.opener || selObj.selectedIndex <= 0) return;
  26.  
  27.   var vl = "";
  28.   var opts = selObj.options;
  29.  
  30.   for ( n = 0 ; n < opts.length ; n++ )
  31.     {
  32.       if (opts[n].selected)
  33.         {
  34.           if (vl.length > 0) vl += ", ";
  35.           vl += opts[n].value;
  36.         }
  37.     }
  38.  
  39.  
  40.      window.opener.document.Qform.NASCOSTO.value = selObj.value;
  41.      window.close();
  42.  
  43. }
  44.  
  45. // -->
  46. </script>
  47.  
  48. </head>
  49.  
  50. <body>
  51.  
  52. <form name="Qform">
  53.  
  54.  
  55.   <select name="ELEMENTO" size="1" onchange="setValue(this);">
  56.   <option value="">Selezionare ELEMENTO</option>
  57.  
  58.     <option value="ALTRO">ALTRO</option>
  59.  
  60.     <option value="BLU">BLU</option>
  61.  
  62.     <option value="GIALLO">GIALLO</option>
  63.  
  64.     <option value="ROSSO">ROSSO</option>
  65.  
  66.     <option value="VERDE">VERDE</option>
  67.  
  68.   </select>
  69.  
  70.       <p align="center">
  71.       <a href="javascript:void(0);" onclick="conferma()">
  72.       <input type="image"src="products.gif" border="0" align="middle" name="I3"></a>
  73.  
  74. </form>
  75.  
  76. </body>
  77. </html>
Aug 30 '09 #9
gits
5,390 Recognized Expert Moderator Expert
ok ... that would validate the input when the link is clicked. so now when you don't need to check when the user just closes the window without a selection (through the close-button - X-button of the window's title bar or with another action like alt+F4) then it would be sufficient. otherwise the mentioned onbeforeunload-event could help ...

kind regards
Aug 30 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1750
by: Dennis | last post by:
This may be easy for most but I can't get this thing to work. I believe I followed all the instructions but when I click on the link no window opens just the default IE page cannot display. Here is exactly what I entered in the link dialog: <a href="javascript:popImage('http://www.sambuccibros.com/carseat.jpg','New Car Seat')"> Is this my problem? Please help.
4
3080
by: Mohit Gupta | last post by:
Hi all, Lately I have been working on an application in VB .net CF for Pocket PC device. I have a small question about Context Menu. When I try to close the window after context menu is poped up, the window does not closes until I click on the window. Below is the code. Hopefully, you can help me out.
2
2221
by: maxrawson | last post by:
Greetings all: I have an asp.net application that is coded mainly in vb.net. I have successfully cut and pasted some javascript into my application that mimicks the datetime picker control in vb. I wanted to try to use that same code for another popup style window that displays a list of airport codes in a datagrid. The desired results would be that when an airport code (the datagrid's key field) is clicked the value would write back...
3
1695
by: Tyrone Slothrop | last post by:
The first question, is this even possible? What I need to do is pass the contents of a PHP web page from a textarea using window.open method to a new browser window and display it. The page has a combination of HTML and PHP. The problem is that the PHP is not being interpreted. This is generally resolved by using the PHP eval() function. However, since the page contents are being passed via JS, the eval is evaluting the JS statement...
2
2078
by: tao lin | last post by:
Hi, all I am using VS2003 under WinXP. My WebApp has a WebForm which has a html form has some search condition textbox, once the user fill in the condition and click submit button. My app will stay in the same WebForm but open a popup window in the browser to show the search results. So I implement like this: private void btnSubmit_Click(object sender, System.EventArgs e)
2
2873
by: Mux | last post by:
I am facing the following problem while exporting data to Word. The current implementation is as described below: I have a JSP file which has a link that enables you to export the data to Word. Clicking on the link invokes a javascript function: function showRTF() { var newWin = window.open("", "newWin","width=900,height=800%,scrollbars=yes,menubar=yes,resizable=yes,too
2
2102
by: Jeff | last post by:
I'm hoping that someone can help me. I know little javascript and only need a very small amount in an asp.net application. I have most of it working with one problem. I'm attempting to open a modal dialog box from a parent window. The dialog box opens fine with the code below associated with the parent. In the child window, I have a button with the simple self.close() code associated with it. Obviously, I want to use the button to close the...
11
5326
by: V S Rawat | last post by:
using Javascript, I am opening a web-based url in a popup window. MyWin1=Window.Open(url, "mywindow") There is a form (form1) in the url in that popup window, I need to submit that form. How do I submit that form1 from the javascript from my current window? Thanks.
2
3157
by: swethak | last post by:
Hi, I am getting the problem the problem with google map in Internet Explorer. This map worked fine in mozilla . When i opened the same map in Internet Explorer i am getting the error message as in alert box as " Internet Explorer cannot open the Internet site http://google.citycarrentals.com.au/viewalllocations.php . Operation aborted". It is working in Mozilla . Here i mentioned my code . I am facing this problem several...
2
3419
by: rexdreamer | last post by:
Gotta problem. I have a page that onload a popup window comesup, within that popup window there is a link to another .htm page. I need that link to display the .htm file in the main browser window.(use the opener keyword to reference the main browser window, and the location.href property to specify the document to be displayed(form.htm)in that window., and slo close the current window. Below is what i have right now, it loads the popup...
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10275
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
10253
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
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
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();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.