473,503 Members | 12,003 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 1856
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
6472
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...
1
6067
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...
7
3570
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>...
3
2944
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...
3
2367
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...
24
6285
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...
13
18657
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
6261
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...
4
1675
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...
3
3226
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...
0
7067
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
7316
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...
0
7449
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...
0
5562
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,...
1
4992
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...
0
4666
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...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
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 ...
1
728
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.