473,651 Members | 3,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[Javascript] Problem with select value

263 Contributor
Hello everyone.

Try this htm page, please:
http://users1.titanichost.com/MiguelRivero61/

This is the code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3.  
  4. <head>
  5.  
  6. <script language="javascript" type="text/javascript">
  7. <!--
  8.  
  9. function Popup(larg,alte,url) 
  10. var w = screen.width; 
  11. var h = screen.height; 
  12. var x = Math.round(w / 2) - Math.round(larg / 2); 
  13. var y = Math.round(h / 2) - Math.round(alte / 2); 
  14. window.open(url,'','width='+larg+',height='+alte+',top='+y+',left='+x+''); 
  15.  
  16.  
  17. //-->
  18. </script> 
  19.  
  20. </head>
  21.  
  22. <body>
  23.  
  24. <form name="myform" action="">
  25.  
  26. <input name="data_ispezione" size="20">
  27.  
  28. <select class=blub size="1" name="Esito_ispezione"    
  29.        onchange="var cc = this.options[this.selectedIndex].value; 
  30.        if(cc=='2' && document.myform.data_ispezione.value!='')
  31.        {Popup(600,200,'Upload_db.asp')}else{alert('Inserire una data!')};">
  32.  
  33.       <option>Seleziona</option>
  34.       <option value="1">Si</option>
  35.       <option value="2">No</option>
  36.       </select>
  37.  
  38.    </form>   
  39. </body>
  40.  
  41. </html> 
If the fields data_ispezione is empty and selected value "No" (2) in the select Esito_ispezione , should not see and open page Upload_db.asp.

Now all values selected in the select Esito_ispezione open the alert, why?

Gracias
MR
Nov 20 '08 #1
7 1861
acoder
16,027 Recognized Expert Moderator MVP
If I understand correctly, you don't want to open the pop-up when the select value is "2"/No or if no text has been input. Is that correct?
Nov 20 '08 #2
viki1967
263 Contributor
If I understand correctly, you don't want to open the pop-up when the select value is "2"/No or if no text has been input. Is that correct?
1) If field data_ispezione is empty and selected value "No" (2) in the select Esito_ispezione NOT open pop-up and OPEN alert "data empty";

2) If field data_ispezione is empty and selected value "Si" (1) in the select Esito_ispezione alert "data empty";

3) If field data_ispezione NOT is empty and selected value "No" (2) in the select Esito_ispezione OPEN pop-up;

thanks x your reply.
Nov 20 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
To satisfy condition 2, you'll need to change the 'else' statement into an 'else if' statement, e.g.
Expand|Select|Wrap|Line Numbers
  1. else if(cc=='1' && document.myform.data_ispezione.value=='') {
  2. alert('...');
  3. }
By the way, it may be better to put the onchange code into a separate function to make things easier.
Nov 20 '08 #4
viki1967
263 Contributor
To satisfy condition 2, you'll need to change the 'else' statement into an 'else if' statement, e.g.
Expand|Select|Wrap|Line Numbers
  1. else if(cc=='1' && document.myform.data_ispezione.value=='') {
  2. alert('...');
  3. }
By the way, it may be better to put the onchange code into a separate function to make things easier.
Sorry but not working...

Expand|Select|Wrap|Line Numbers
  1. onchange="var cc = this.options[this.selectedIndex].value; else if(cc=='2' && document.myform.data_ispezione.value!=''){Popup(600,200,'Upload_db.asp')}else{this.selectedIndex=0; alert('Inserire una data!')};">
1) Field data empty: selected value 1 or value 2 in the select open the alert: IT'S OK

2) Field data NOT empty: selected value 2 in the select OPEN pop-up; IT'S OK

3) Field data NOT empty: selected value 1 in the select open the alert; IT'S WRONG because Field data is NOT empty...
Nov 20 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
You haven't added the if statement to the else, but anyway what you should really be doing is checking the input field first, e.g.
Expand|Select|Wrap|Line Numbers
  1. onchange="var cc = this.options[this.selectedIndex].value; if(document.myform.data_ispezione.value=='') {this.selectedIndex=0; alert('Inserire una data!')} else if (cc=='2') {Popup(600,200,'Upload_db.asp')};">
Nov 20 '08 #6
viki1967
263 Contributor
You haven't added the if statement to the else, but anyway what you should really be doing is checking the input field first, e.g.
Expand|Select|Wrap|Line Numbers
  1. onchange="var cc = this.options[this.selectedIndex].value; if(document.myform.data_ispezione.value=='') {this.selectedIndex=0; alert('Inserire una data!')} else if (cc=='2') {Popup(600,200,'Upload_db.asp')};">
thanks genius !!!!

Bye
Viki
Nov 20 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
Glad it's working. Sometimes you have to rethink what you're doing to make solving a problem a little easier.
Nov 20 '08 #8

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

Similar topics

5
6481
by: Tim | last post by:
I've been working on this for over a week now, and just can't get this figured out. Hoping one of you gurus can help me out here. I have an xml data island that I'm representing on an htm page as an expandable menu. Got that working, but now I need to add sorting and searching abilities to the menu. I am hoping to do this with xsl but can't get it to work. Is this because of the way I've formed my xml, having the children within the...
1
6083
by: bin_P19 P | last post by:
the code i have got is as follows and now im stuck <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Shopping Cart</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="StyleSheet" href="css/style.css" type="text/css">
7
3593
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
3
2961
by: Richard | last post by:
I have tried to create a javascript puzzle where by the grid is filled with numbers from 1 to 26 and another grid listed 1 to 26 where each number relates to a letter. Once you figure out the number to letter sequence in the 2nd grid, you fill all the squares labeled with that number....poor explanation but the HTML will explain it! What I can't seem to manage to work is getting the javascript to take the selected letters and place them...
3
2372
by: bloc | last post by:
I am programming an interactive CV using xml, xslt and java script. The page consists of a header which contains links to various 'sections' on the xml cv, a left and right menu, and a central panel. The central panel is intended to display the main content of the cv: when an anchor is selected from the header then the detail is supposed to appear. The javascript is supposed to select the appropriate section 'onclick' and output it....
24
6320
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to have on his site, a Javascript Calculator for working out the cost of what they want, for example: 1 widget and 2 widglets = £5.00
13
18677
by: monomaniac21 | last post by:
hi i want to be able to trigger a javascript style popup alert in php (i want a message displayed on the actual page) is this possible?
3
6276
by: bhanubalaji | last post by:
hi, I am unable to disable the text(label) in javascript..it's working fine with IE,but i am using MOZILLA.. can any one help regarding this.. What's the wrong with my code? I am sending my code here.. Thanks in Advance... Regards
4
1692
by: JLupear | last post by:
My friend and I are trying to start a business and are writing a website of our own. We have been trying to create an online estimator and are having trouble with writing the javascript that is to handle the form data. I am having trouble capturing the form data for use using the onsubmit operator. We have written all of the options using list boxes using numbers as the values. I have attempted to create a user defined function to caculate...
3
3238
by: Venturini | last post by:
I am trying to put together a web page where the customer makes choices of products and is then given a total. I am extremely new to Javascript and have managed to get as far as I have from web searches for scripts and html and adapted them. I need to know the principles of how to disable certain options based on other selections within the form. I have attached my script and html below to help. For example of a customer selects (BASIC...
0
8361
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
8278
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
8584
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5615
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
4144
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
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1912
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.