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

Problem with form in window popup

263 100+
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 1940
gits
5,390 Expert Mod 4TB
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 100+
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 Expert Mod 4TB
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 100+
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 Expert Mod 4TB
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 100+
OK, but can you tell me how I modify my code?
Aug 29 '09 #7
gits
5,390 Expert Mod 4TB
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 100+
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 Expert Mod 4TB
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
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...
4
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...
2
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...
3
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...
2
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...
2
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....
2
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...
11
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. ...
2
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...
2
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...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.