473,834 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Onchange Event in Dropdown

92 New Member
Hi Friends,
I have a problem with OnChange event, Please help me out in coding the below requirement.
I have a drop down box with 3 items: India,United States,South Africa. If I select India(for India alone) a pop up window should come up with some text/question("Are you an Indian Citizen?"), Yes/No should be the only options. If the user clicks on Yes, some value should be saved in a variable which i need to save it in my database so as to maintain a record that a question was asked and answered.

Please help me out. Thanks inadvance.

Jun 9 '09 #1
41 11283
8,658 Recognized Expert Moderator Expert
you could use window.confirm( )?
Jun 11 '09 #2
92 New Member
Thanks for the reply.
if the user clicks OK, i want to store some value in a variable and call it in a text box.. How can achieve this?
Jun 11 '09 #3
92 New Member
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script language="javascript">
  4. function ConSub()
  5.   {
  6.    var result;
  7.    var w = document.frm.Country.selectedIndex;
  8.    var selected_text = document.frm.Country.options[w].text;
  9.      if (selected_text == "South Africa")
  10.         'result=window.confirm("Do you have a Emp certificate?");
  11.                  if (result== true)
  12.               // i want to store some value sayYES in a variable and call this variable in a text box//
  13. else 
  14. return false;
  15. }
  16. <form name="frm">
  17. <select name="Country" onchange="return ConSub()">
  18. <option value="India">India
  19. <option value="South Africa">South Africa
  20. </select>
  21. </form>
  22. </body>
  23. </html>
Please edit/comment on how can i track that user has clicked OK or cancel.i want store this in a variable.
Jun 11 '09 #4
160 New Member
this code may be helpfull for you
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function country (value)
  3. {
  4. if(window.confirm("Are You "+value+" citizan"))
  5.      {
  6.      country = value;
  7.       return true;
  8.      }
  9. else
  10.       return false;
  11. }
  12. </script>
  14. <select name="country" id="country" onchange="return country(this.value)">
  15. <option value="0">Select Country</option>
  16. <option value="India">India</option>
  17. <option value="United States">United States</option>
  18. <option value="South Africa">South Africa</option>
  19. </select>
i need to know how can value of country can be assign to a php variable so that it can be used for insertion in database
Jun 11 '09 #5
8,658 Recognized Expert Moderator Expert
  1. submit the form
  2. submit an AJAX request
Jun 11 '09 #6
92 New Member
Thanks again..
The above code will make a cofirm box pop up for every item in the drop down, but i require this function to get fired only when INDIA is selected frm the list.
Not for all the items in the drop down.
Jun 11 '09 #7
160 New Member
any other way like
Expand|Select|Wrap|Line Numbers
  1.  if(window.confirm("Are You "+value+" citizan"))
  2.       {
  3.     <?php
  4.     $country = echo '<script type="text/JavaScript"> echo value; </script>'; 
  5.     ?>      
  7.        return true;
  8.       }
Jun 11 '09 #8
92 New Member
I am using ASP pages and javascript, not asp.net or php coding.
Jun 11 '09 #9
8,658 Recognized Expert Moderator Expert
that doesn't change the general idea, only the syntax.
Jun 11 '09 #10

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

Similar topics

by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function init() {
by: Ryan McGeary | last post by:
In a <select> drop-down, the onchange event isn't called when scrolling through the dropdown using the mouse-wheel and when crossing over a new <optgroup>. Using the example below, notice how the onchange event isn't called when mouse wheel scrolling between A3 and B1, but it works properly when scrolling between A1 and A2. E.g. ------------------------------------------
by: Asit | last post by:
In JavaScripts checks for an onChange event against the value of the textbox at the time of the last onChange event. Since an onChange Event never fired after you changed the text first time , suppose we put the same value in the text box then no event is fired. If we put some other value then it became fired... It wouldn't fire if we put the same value... I don't want to use onBlur etc... Isthere any solution with onChange Event...?
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is dependant on data collected in the code behind on the server. I have set AutoPostback to false for the controls and added lines such as cboMyCombo1.Attributes.Add("onchange", "MyCombos_OnChange('1')"); in the Page_Load event, which is rendered OK...
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having a couple of problems, which I'll try to describe. But this e-mail will only reproduce one of them, in a "short" example. What I'm generally doing is having each form entry contained in a div, which as a label, an input with some event handlers,...
by: b_naick | last post by:
I realize that the onChange event for a drop down can be trapped as follows: <select name="myDropDown" onChange="somefunc"> Is it possible to trap the onChange event outside of the select statement? Something like this: document.forms.myDropDown.onChange = somfunc;
by: countocram | last post by:
hi! Im having a problem retaining the inputs on my text fields. When i selected an option from a dropdown list with an onChange=location.. event. What happen is that, everytime I choose an option the page will reload then the inputs on my text field will disappear... sample HTML: <INPUT type="text" name="help_title" size="50"> <textarea cols="50" rows="15" name="help_content"></textarea> <select name="main_topic"...
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays prodcut anme have used ajax to avoid refreshing of page this works fine 2.now i have created one row with checkbox|select box|text|text|text|text| where in the select box values are fetched from table here also i have used ajax for getting the m_name...
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: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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: 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...
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: 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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.