premiere1
asked on
disable an <a tag with javascript
I am doingn an application and i have a list of items for selection using:
<a href="javascript:additem(' itemid')" ID="Xitemid">itemid</a>
in my javascript after processing my item, I am doing:
document.getElementById("X itemid").d isabled = true;
This lowlights the link, but it is still able to be clicked.
Can I disable the link so that it cannot be clicked without changing the href information? I can do that, but if I enable it, i will need to change the href info back.
thanks
<a href="javascript:additem('
in my javascript after processing my item, I am doing:
document.getElementById("X
This lowlights the link, but it is still able to be clicked.
Can I disable the link so that it cannot be clicked without changing the href information? I can do that, but if I enable it, i will need to change the href info back.
thanks
Add an onClick="return false;"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What about :
Test page :
document.getElementById("Xitemid").href = "javascript:void(0);";
Test page :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
window.onload = function() {
disableLink("Xitemid");
}
function disableLink(id) {
document.getElementById("Xitemid").href = "javascript:void(0);";
}
function enableLink(id) {
document.getElementById(id).href = "javascript:void(" + document.getElementById(id).getAttribute("value") + ");";
}
</script>
</head>
<body>
<a href="javascript:additem('itemid')" ID="Xitemid" value="itemid">itemid</a>
</body>
</html>
Try something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q__26825862.html</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready( function () {
$("#toggle").click( toggle );
});
function toggle() {
var anchor = $("#Xitemid");
if ( anchor.attr("href") ) {
anchor.attr( { "rel": anchor.attr("href") } );
anchor.removeAttr( "href" );
} else {
anchor.attr( { "href": anchor.attr("rel") } );
anchor.removeAttr( "rel" );
}
}
</script>
</head>
<body>
<a href="javascript:alert('itemid')" ID="Xitemid">itemid</a>
<input id="toggle" type="button" value="Toggle" />
</body>
</html>
ASKER
sjklein42, an FYI, your response did not wrap in the box. I had to look at the source to see it.
I liked your solution. I did this:
<a href="javascript:{if (! this.disabled) {move('BOXED','3004230501' ,'500')}}" ID="O3004230501">300423050 1</a>
and for the javascript, I did this:
function move(type,order,qty){
document.getElementById("O "+order).d isabled = true;
and it worked well.
I tried:
<a href="javascript:{if (! this.disabled) {move('BOXED',this,'500')} }" ID="O3004230501">300423050 1</a>
and this
function move(type,this,qty){
this.disabled = true;
but it did not work, can you tell me why?
I liked your solution. I did this:
<a href="javascript:{if (! this.disabled) {move('BOXED','3004230501'
and for the javascript, I did this:
function move(type,order,qty){
document.getElementById("O
and it worked well.
I tried:
<a href="javascript:{if (! this.disabled) {move('BOXED',this,'500')}
and this
function move(type,this,qty){
this.disabled = true;
but it did not work, can you tell me why?
ASKER
This should have been:
function move(type,obj,qty){
obj.disabled = true;
not sure if using "this" would cause a problem.
function move(type,obj,qty){
obj.disabled = true;
not sure if using "this" would cause a problem.