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 - <script language="javascript" type="text/javascript">
-
<!--
-
-
function setValue(selObj)
-
{
-
-
if (!window.opener || selObj.selectedIndex <= 0) return;
-
-
var vl = "";
-
var opts = selObj.options;
-
-
for ( n = 0 ; n < opts.length ; n++ )
-
{
-
if (opts[n].selected)
-
{
-
if (vl.length > 0) vl += ", ";
-
vl += opts[n].value;
-
}
-
}
-
-
window.opener.document.Qform.NASCOSTO.value = selObj.value;
-
-
-
window.close();
-
-
}
-
-
// -->
-
</script>
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?
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...
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
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
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.
OK, but can you tell me how I modify my code?
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
OK, I understand...
I write this code... working but I'am not sure it is a conform solution to the problem ... - <html>
-
<head>
-
-
<title>Popup</title>
-
-
<script language="javascript" type="text/javascript">
-
<!--
-
-
-
function conferma(){
-
-
if(document.Qform.ELEMENTO.value.length <= 0)
-
{
-
alert("Compila tutti i campi");
-
}
-
else
-
{
-
document.Qform.submit();
-
}
-
}
-
-
-
function setValue(selObj)
-
{
-
-
if (!window.opener || selObj.selectedIndex <= 0) return;
-
-
var vl = "";
-
var opts = selObj.options;
-
-
for ( n = 0 ; n < opts.length ; n++ )
-
{
-
if (opts[n].selected)
-
{
-
if (vl.length > 0) vl += ", ";
-
vl += opts[n].value;
-
}
-
}
-
-
-
window.opener.document.Qform.NASCOSTO.value = selObj.value;
-
window.close();
-
-
}
-
-
// -->
-
</script>
-
-
</head>
-
-
<body>
-
-
<form name="Qform">
-
-
-
<select name="ELEMENTO" size="1" onchange="setValue(this);">
-
<option value="">Selezionare ELEMENTO</option>
-
-
<option value="ALTRO">ALTRO</option>
-
-
<option value="BLU">BLU</option>
-
-
<option value="GIALLO">GIALLO</option>
-
-
<option value="ROSSO">ROSSO</option>
-
-
<option value="VERDE">VERDE</option>
-
-
</select>
-
-
<p align="center">
-
<a href="javascript:void(0);" onclick="conferma()">
-
<input type="image"src="products.gif" border="0" align="middle" name="I3"></a>
-
-
</form>
-
-
</body>
-
</html>
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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.
|
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...
|
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...
|
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)
| |
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
|
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...
|
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.
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |