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.
Regards,
41 11212
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?
- <html>
-
<head>
-
<script language="javascript">
-
function ConSub()
-
{
-
var result;
-
var w = document.frm.Country.selectedIndex;
-
var selected_text = document.frm.Country.options[w].text;
-
if (selected_text == "South Africa")
-
'result=window.confirm("Do you have a Emp certificate?");
-
if (result== true)
-
// i want to store some value sayYES in a variable and call this variable in a text box//
-
else
-
return false;
-
}
-
<form name="frm">
-
<select name="Country" onchange="return ConSub()">
-
<option value="India">India
-
<option value="South Africa">South Africa
-
</select>
-
</form>
-
</body>
-
</html>
Please edit/comment on how can i track that user has clicked OK or cancel.i want store this in a variable.
this code may be helpfull for you -
<script language="javascript">
-
function country (value)
-
{
-
if(window.confirm("Are You "+value+" citizan"))
-
{
-
country = value;
-
return true;
-
}
-
else
-
return false;
-
}
-
</script>
-
-
<select name="country" id="country" onchange="return country(this.value)">
-
<option value="0">Select Country</option>
-
<option value="India">India</option>
-
<option value="United States">United States</option>
-
<option value="South Africa">South Africa</option>
-
</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
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.
any other way like -
if(window.confirm("Are You "+value+" citizan"))
-
{
-
<?php
-
$country = echo '<script type="text/JavaScript"> echo value; </script>';
-
?>
-
-
return true;
-
}
-
I am using ASP pages and javascript, not asp.net or php coding.
that doesn't change the general idea, only the syntax.
I agree... According my script,
var w = document.frm.Country.selectedIndex;
var selected_text = document.frm.Country.options[w].text;
Variable "selected_text" contian the current item selected from the drop down, now i will check a condition (if selected_text=="India"), if yes a confirm box will popup.
now if the user clicks OK/CANCEL, i need to store a true/false value in a varialbe and then assign it to asp variable or a text box. How can i do this
Dormilich please can you tell me correct syntax. my above code is not executed correctly
I know neither ASP nor ASP.NET
no i am asking about php and javascript. what is mistake in my following code. where variable 'value' is javascript variable -
<?php
-
$country = echo '<script type="text/JavaScript"> echo value; </script>';
-
?>
-
Your code executed correctly but the confirm box is popped up for each item clicked in the drop down.. I need this to happen only when i click India not for all... I have no idea how to assign a Javascript variable to a html/asp text box.
@waqasahmed996
echo is not a function and thus cannot be assigned to a variable.
thanks chandhseke but i am asking from Dormilich
The output of your above code is as follows..
while i select INDIA from drop down, a confirm box comes up with a question: Are you a INDIA citizen( where value is taken as INDIA).. But this is not my concern, my concern ihere s when the user clicks OK or CANCEL then i want this action to be recorded or stored in a variable, and this value should be stored in a text box
@chandhseke
To assign it to a text box: - document.getElementById("textboxid").value = val;
This would require a submit to be passed to ASP. Another option is to pass it in the URL and change the page immediately: - location.href = "asppage.asp?val=" + val;
If you want to avoid a page reload, use Ajax.
@chandhseke
what do you mean by "text box"? a <textarea> or a <input> or a <div> element?
you can write like
document.getElementById('txtbox').innerHTML = 'INDIA'
Dormilich i remove echo from my code even then it is not working
@waqasahmed996
to get output you have to use echo or one of the print() functions
sorry Dormilich i am still unable to understand. please tell me what should i write exactly -
<?php
-
$country = echo '<script type="text/JavaScript"> value; </script>';
-
?>
-
I guess -
<?php
-
echo '<script type="text/JavaScript"> // whatever code </script>';
-
?>
-
will do.
EDIT: if your problem is not related to chandhseke's problem, I'll move the corresponding posts to a new thread in the PHP forum.
@waqasahmed996
Besides the PHP problem, you're mixing JavaScript and PHP incorrectly. You can use PHP (or any server-side language) to generate JavaScript code during page load, but you can't use this kind of code to run PHP after the page has loaded.
In vbscript, i am using message box If the user clicks OK button.. I want to assing a value to a text box <input>..Please help me out in this - <Script lang="VBScript>
-
dim a
-
dim res= Yes
-
a=MsgBox("you pressed ok",VbYesNo)
-
-
if a = VbYes then
-
-
<i want to assign the variable "res" to a text box below>
-
</script>
-
-
<html>
-
<head><body>
-
<input type="text" name="test" value=''>
-
</head></html>
Two questions:
1. Is this related to the original problem?
2. Why are you using VBScript when JavaScript is more cross-browser friendly?
PS. please use [code] tags when posting code.
As there is NO window object with YES and NO buttons in Javascript, i am making use of both Javascript and VB script..
In javascript i am using selectedIndex to track the selected item from the drop down, within IF conditon i am calling VBscript function(contains a MsgBox) if the result is true...
Now within VBscript i need to write a condition, If the user clicks on Yes button then i want to assign some value to a textbox so that i can save this text box value in the database.
You do realise that this would restrict your site to IE only? You can phrase your question so that the options for confirm() (OK/Cancel) are suitable. Are you sure you still want to go with VBScript?
If you do, the method will be similar to what has been suggested earlier. Set the value of the text box like this: - document.getElementById("textboxid").value = val;
where "textboxid" is the ID of the text box and val is the value that needs to be assigned.
Thanks for the reply.
But as per the requirement, YES or NO should be the only options..that is the reason i am using VBscript... Anyways i will speak to the requestors regarding the above subject... If i am using VBscript what will be the syntax in VBscript to assign a value to a text box..??
I don't know if you can use document.getElementById(), but if you add a form element, you can use the following syntax: - document.formname.fieldname.value = res;
Example : If i add a text box named as text1 to the existing form form1, then the syntax would be :
dim res= 'YES"
Document.form1.text1.value= res...
Yes, but your page code is a bit messed up, e.g. the <head> tags are in the wrong place and the script is outside the HTML tag. You also need to put your code inside a function to be run when an event takes place, e.g. when a button is clicked.
As suggested i had made the below code changes in my form, when i tested my database it contains Blank value..Please Review the code below and advise - <html>
-
<head>
-
<script language="Javascript">
-
function fun()
-
{
-
var res;
-
var w=document.form1.SetUpCountry.selectedIndex;
-
var selected_text=document.form.SetUpCountry.options[w].value;
-
if (selected_text == "South Africa")
-
{
-
return pop()
-
}
-
else
-
return false;
-
}
-
</script>
-
-
<script language="VBScript">
-
function pop()
-
dim b
-
dim result
-
dim answer
-
result = "Yes"
-
answer = "No"
-
b=msgbox("Do you have a BEE certificate?",vbYesNo,"New Supplier Setup")
-
if b = vbYes then
-
document.form1.Text1.value = result
-
Else
-
document.form1.text1.value = answer
-
end if
-
end function
-
</script>
-
</head>
-
<title>Supplier Request</title>
-
<body>
-
<form name="form1">
-
----------------------
-
------------------
-
<select name="SetUpCountry" onchange="fun()">
-
<option value="India">India</option>
-
<option value="South Africa">South Africa</option>
-
<option value="Germany">Germany</option>
-
</select>
-
</form>
-
</body>
-
</html>
Here is another code snippet, save this code and run it in your browser... A drop down and a text box will be displayed. When you select an item from the drop down list, a MsgBox will pop up and when you click on Yes Button the variable (a =YES) value should come into the text box else if you click on NO button varibale (c = NO) should come into text box...I have coded it as per your suggestion but didnt worked to me.. Please edit the below code... Thanks in advance - <html>
-
<head>
-
<script type="text/vbscript">
-
function fun
-
dim a
-
dim b
-
dim c
-
c = "No"
-
a = "Yes"
-
b=MsgBox("Message",VbYesNo)
-
if b = VbYes then
-
document.myform.text1.value=a
-
else
-
document.myform.text1.value=c
-
End if
-
document.write(a)
-
End function
-
</script>
-
<body>
-
<form name="myform">
-
<select name="country" onchange="return fun()">
-
<option value="india">india</option>
-
<option value="india">SA</option>
-
</select>
-
<input type="text" name="text1" value=" ">
-
</form>
-
</body>
-
</html>
Three problems I notice:
1. Both options have the same value "india".
2. The 'return' in onchange. Remove it.
3. The document.write() statement which will cause the page to be reopened and overwritten. Remove that line.
PS. please use [code] tags around your code. See How to Ask a Question.
@chandhseke
To actually make changes to the database, you will need to submit the form and your action page (server-side script) should connect to and update the database.
Hi folks,
Thanks a lot for your help on this..It worked for me.
Many thanks
No problem. Glad it's now working :)
Many thanks again..
I have one more small question to you, how can i validate the text box value in ASP against a database table (Written using VBScript) before submission of the Online form??
Background: I have an online business form, while a new requestor enters thier ID # it should be validated against a database table to check whether the ID# exists in the database, if NO an error msg should be displayed.
Lets make a long story into small, i am working as a Application Maintanence engineer and this is the new requirement which i havent done before..Please guide me through as you did with last Thread..Many Thanks
Your question is no longer relevant to this thread, nor to JavaScript. Repost your question in the ASP forum where you will get a better response.
Ok Sorry for that.. Thank you
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...
|
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...
|
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 ,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |