Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I have an HTML Select(Dropdown) control in my web form with the following options:

HTML
<select class="body_text" name="critical">
   <option value="Select"> Select </option>
   <option value="LOW"> Low </option>
   <option value="NORMAL"> Normal </option>
   <option value="HIGH"> High </option>
   <option value="CRITICAL"> Critical </option>      
</select>


As in ASP Server control its much easier to handle dropdownlist selection change events.
Just like that I want to Display the text in a DIV on the following Scenario using HTML Select Control and cannot use runat="server" in the control:

If the Selection is LOW the DIV should display:
C#
"Priority Low: The selection is Low"


If the Selection is NORMAL the DIV should display:
C#
"Priority Normal:The selection is Normal"


If the Selection is HIGH the DIV should display:
C#
"Priority High: The selection is High"


If the Selection is CRITICAL the DIV should display:
C#
"Priority Critical: The selection is Critical"



How can I apply this scenario using JavaScript. Please Help.

Thanks,
AR.
Posted
Updated 12-May-14 1:05am
v3
Comments
Karthik_Mahalingam 20-Dec-13 3:50am    
you have one DIV or 4 div's ??

With the help of Jquery selector you can achieve this:-

JavaScript
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" language="javascript">

$(function(){

$('.body_text').change(function(){
var a = $(this).val();
var msg = 'Priority "+ a +": The selection is "+ a +"';
$('div').html(msg); // selector for div

});

});
</script>


This will resolve your problem....
 
Share this answer
 
v2
Comments
AR547 20-Dec-13 3:53am    
Brilliant... (y)
Jain Nishant 20-Dec-13 4:40am    
Thanks...
Next time I will try myself first then put my question on CodeProject. Why I always give up :/

Finally solved it through javascript as I asked.. :)

HTML
<script language="JavaScript">

var DivTxt = new Array()
DivTxt[0] = "Please Select Priority"
DivTxt[1] = "Priority Low: The selection is Low"
DivTxt[2] = "Priority Normal: The selection is Normal"
DivTxt[3] = "Priority High: The selection is High"
DivTxt[3] = "Priority Critical: The selection is Critical"

function getText(slction){
txtSelected = slction.selectedIndex;
document.getElementById('textDiv').innerHTML = DivTxt[txtSelected];
}
</script>


<Select class="body_text" name="critical" onchange="getText(this)">
<option value="Select"> Select </option>
   <option value="LOW"> Low </option>
   <option value="NORMAL"> Normal </option>
   <option value="HIGH"> High </option>
   <option value="CRITICAL"> Critical </option>      
</select>
<div id="textDiv" style="color:Green; font-family:Calibri; font-size:small; font-weight:bold"> </div>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900