Disable/enable icon.gif
Question posted by: viki1967
(Familiar Sight)
on
August 28th, 2008 09:13 AM
Disable/enable icon.gif
Hi all.
I have this form in the page.htm:
-
<form action="form.asp" method="post" onsubmit="return(validateForm(this));">
-
-
<select size="1" name="t_im" onchange="Form()">
-
<option value="">Select value</option>
-
<option value="A">A</option>
-
<option value="C">C</option>
-
<option value="Ca">Ca</option>
-
<option value="Cav">Cav</option>
-
</select>
-
-
<input type="text" name="e_gu" size="10" readonly>
-
<a href="javascript:Form()">
-
<img src="icon_1.gif" border="0"></a>
-
-
<select size="1" name="c_fu">
-
<option value="">Select value</option>
-
<option value="YES">YES</option>
-
<option value="NO">NO</option>
-
</select>
-
-
<input type="text" name="c_ma" size="10" readonly>
-
<a href="javascript:Form()">
-
<img src="icon_2.gif" border="0"></a>
-
-
</form>
I need:
1) If select name="t_im" value is NULL ( "" ) disable icon_1.gif
2) If select name="t_im" value NOT is NULL ( "" ) enable icon_1.gif
3) If select name="c_fu" value is NULL ( "" ) OR value is "YES" disable icon_2.gif
4) If select name="c_fu" value is "NO" enable icon_2.gif
Can you help me ?
kind regards
viki
10
Answers Posted
Wether u need it as disabled or hidden.
Regards
Ramanan Kalirajan
Quote:
Originally Posted by RamananKalirajan
Wether u need it as disabled or hidden.
Regards
Ramanan Kalirajan
I need disabled.
thanks x your reply
viki
Quote:
Originally Posted by viki1967
I need disabled.
thanks x your reply
viki
just check, the selected value in the function. Give id to each and every object u use. Here is an example code
- <html>
-
<head>
-
<script type="text/javascript">
-
function doThis()
-
{
-
//alert("hai");
-
var x = document.getElementById('mySelect').selectedIndex;
-
alert(document.getElementById('mySelect').options[x].value);
-
if(document.getElementById('mySelect').options[x].value<1)
-
document.getElementById('myImg').disabled=true;
-
}
-
</script>
-
</head>
-
<select id="mySelect" size="10" onclick="doThis()">
-
<option value="0">Select a Value</option>
-
<option value="1">Select 1 Value</option>
-
<option value="2">Select 2 Value</option>
-
<option value="3">Select 3 Value</option>
-
</select>
-
<br/><br/><br/>
-
<img src="demo.jpg" id="myImg">
-
</html>
-
By using this code I cant see the image disabling, same replaced by a text box is working. I hope disable property is not supported for Img. Instead of disabling u can use hidden property (my suggestion).
Regards
Ramanan Kalirajan
Sorry buy your example not working in my case:
- <html>
-
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
-
-
<script type="text/javascript">
-
function doThis()
-
{
-
-
var x = document.getElementById('mySelect').selectedIndex;
-
alert(document.getElementById('mySelect').options[x].value);
-
-
if(document.getElementById('mySelect').options[x].value < 1)
-
document.getElementById('myImg').disabled=true;
-
}
-
</script>
-
-
-
</head>
-
-
<body>
-
-
<form action="form.asp" method="post" onsubmit="return(validateForm(this));">
-
-
<select id="mySelect" size="1" name="t_im" onchange="Form()" onclick="doThis()">
-
<option value="">Select value</option>
-
<option value="A">A</option>
-
<option value="C">C</option>
-
<option value="Ca">Ca</option>
-
<option value="Cav">Cav</option>
-
</select>
-
-
<input type="text" name="e_gu" size="10" readonly>
-
<a href="javascript:Form()">
-
<img id="myImg" src="icon_1.gif" border="0"></a>
-
-
<select size="1" name="c_fu">
-
<option value="">Select value</option>
-
<option value="YES">YES</option>
-
<option value="NO">NO</option>
-
</select>
-
-
<input type="text" name="c_ma" size="10" readonly>
-
<a href="javascript:Form()">
-
<img src="icon_2.gif" border="0"></a>
-
-
</form>
-
-
</body>
-
-
</html>
Sorry buy your example not working in my case:
- <html>
-
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
-
-
<script type="text/javascript">
-
function doThis()
-
{
-
-
var x = document.getElementById('mySelect').selectedIndex;
-
alert(document.getElementById('mySelect').options[x].value);
-
-
if(document.getElementById('mySelect').options[x].value < 1)
-
document.getElementById('myImg').disabled=true;
-
}
-
</script>
-
-
-
</head>
-
-
<body>
-
-
<form action="form.asp" method="post" onsubmit="return(validateForm(this));">
-
-
<select id="mySelect" size="1" name="t_im" onchange="Form()" onclick="doThis()">
-
<option value="">Select value</option>
-
<option value="A">A</option>
-
<option value="C">C</option>
-
<option value="Ca">Ca</option>
-
<option value="Cav">Cav</option>
-
</select>
-
-
<input type="text" name="e_gu" size="10" readonly>
-
<a href="javascript:Form()">
-
<img id="myImg" src="icon_1.gif" border="0"></a>
-
-
<select size="1" name="c_fu">
-
<option value="">Select value</option>
-
<option value="YES">YES</option>
-
<option value="NO">NO</option>
-
</select>
-
-
<input type="text" name="c_ma" size="10" readonly>
-
<a href="javascript:Form()">
-
<img src="icon_2.gif" border="0"></a>
-
-
</form>
-
-
</body>
-
-
</html>
Quote:
Originally Posted by viki1967
Sorry buy your example not working in my case:
- <html>
-
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
-
-
<script type="text/javascript">
-
function doThis()
-
{
-
-
var x = document.getElementById('mySelect').selectedIndex;
-
alert(document.getElementById('mySelect').options[x].value);
-
-
if(document.getElementById('mySelect').options[x].value < 1)
-
document.getElementById('myImg').disabled=true;
-
}
-
</script>
-
-
-
</head>
-
-
<body>
-
-
<form action="form.asp" method="post" onsubmit="return(validateForm(this));">
-
-
<select id="mySelect" size="1" name="t_im" onchange="Form()" onclick="doThis()">
-
<option value="">Select value</option>
-
<option value="A">A</option>
-
<option value="C">C</option>
-
<option value="Ca">Ca</option>
-
<option value="Cav">Cav</option>
-
</select>
-
-
<input type="text" name="e_gu" size="10" readonly>
-
<a href="javascript:Form()">
-
<img id="myImg" src="icon_1.gif" border="0"></a>
-
-
<select size="1" name="c_fu">
-
<option value="">Select value</option>
-
<option value="YES">YES</option>
-
<option value="NO">NO</option>
-
</select>
-
-
<input type="text" name="c_ma" size="10" readonly>
-
<a href="javascript:Form()">
-
<img src="icon_2.gif" border="0"></a>
-
-
</form>
-
-
</body>
-
-
</html>
In the if condition u have kept the value as 1 itself change for ur value and try it out. But the thing I am not able to diable an image. Just try hiding it
Regards
Ramanan Kalirajan
By disabling, do you mean that you want to disable the link?
Quote:
Originally Posted by acoder
By disabling, do you mean that you want to disable the link?
Yes, I disable the link href.
This is my solution on the problem, check please:
-
-
<html>
-
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
-
-
<script type="text/javascript">
-
-
function CheckIcon1(ss){
-
var ok=false
-
if(ss.options[ss.selectedIndex].value==''){
-
document.getElementById('icon1').onclick=Function( 'return false')
-
document.getElementById('img_icon1').src='icon_1.g if'
-
}
-
else{
-
document.getElementById('icon1').onclick=Function( 'return true')
-
document.getElementById('img_icon1').src="icon_2.gif'
-
ok=true
-
}
-
return ok
-
}
-
-
function CheckIcon2(ss){
-
var ok=false
-
if(ss.options[ss.selectedIndex].value=='NO'){
-
document.getElementById('icon2').onclick=Function( 'return true')
-
document.getElementById('img_icon2').src='icon_1.g if'
-
ok=true
-
}
-
else{
-
document.getElementById('icon2').onclick=Function( 'return false')
-
document.getElementById('img_icon2').src='icon_2.g if'
-
}
-
return ok
-
}
-
-
-
function Form(theUrl, percSize)
-
-
{
-
-
var width = 400;
-
var height = 200;
-
var left = Math.floor((screen.width-width)/2);
-
var top = Math.floor((screen.height-height)/2);
-
-
window.open(theUrl,'popup','width='+width+',height ='+height+',top='+top+',left='+left);
-
-
}
-
-
</script>
-
-
</head>
-
-
<body>
-
-
<form action="form.asp" method="post">
-
-
<select size="1" name="t_im" onchange="if(CheckIcon1(this))Form('test.htm', '');">
-
<option value="">Select value</option>
-
<option value="A">A</option>
-
<option value="C">C</option>
-
<option value="Ca">Ca</option>
-
<option value="Cav">Cav</option>
-
</select>
-
-
<input type="text" name="e_gu" size="10" readonly>
-
<a id="icon1" href="javascript:Form('test.htm')" onclick="return false">
-
<img id="img_icon1" src="icon_1.gif" border="0"></a>
-
-
<select size="1" name="c_fu" onchange="CheckIcon2(this);">
-
<option value="">Select value</option>
-
<option value="YES">YES</option>
-
<option value="NO">NO</option>
-
</select>
-
-
<input type="text" name="c_ma" size="10" readonly>
-
<a id="icon2" href="javascript:Form('test.htm')" onclick="return false">
-
<img id="img_icon2" src="icon_2.gif" border="0"></a>
-
-
</form>
-
-
</body>
-
-
</html>
Set href to a real URL, i.e. "test.htm" in this case, and make the JavaScript function call in the onclick. To remove an onclick, set it to null, though here you would want to just set it to return false.
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 197,015 network members.
Top Javascript / DHTML / Ajax Contributors
|