using javascript to alter link attributes in mozilla firefox

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
d_d
Forum Commoner
Posts: 33
Joined: Wed Jul 07, 2004 4:56 pm
Location: UK

using javascript to alter link attributes in mozilla firefox

Post by d_d »

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>links</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript">
<!--
function preview()
&#123;
	document.getElementById("preview").innerText = document.add_link.text.value;
	document.getElementById("preview").title = document.add_link.title.value;
	document.getElementById("preview").href = document.add_link.href.value;
&#125;
//-->
</script>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
<form name="add_link" action="link.php" method="post">
<div>preview : <a id="preview" href="" title=""></a></div>
<div><br>href <input type="text" size="67" name="href" value="http://"></div>
<div><br>title <input type="text" size="67" name="title"></div>
<div><br>text <input type="text" size="67" name="text"></div>
<div><br><input type="button" value="preview link" onclick="javascript:preview()"></div>
</form>
</body>
</html>
I have a page that allows me and other visitors to submit links that are randomly show at the bottom of each page.
The problem is the preview doesn't work in firefox as it uses stuff only available to msie. I did a bit of searching and I can't see anyway to alter the link attributes that will work with firefox. Is there anyway to get it to work with both msie and firefox?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try innerHTML
d_d
Forum Commoner
Posts: 33
Joined: Wed Jul 07, 2004 4:56 pm
Location: UK

Post by d_d »

Thanks :) got it working now.

Code: Select all

<script type="text/javascript">
<!--
function preview()
&#123;
   document.getElementById("preview").href = document.add_link.href.value;
   document.getElementById("preview").title = document.add_link.title.value;
   document.getElementById("preview").innerHTML = document.add_link.text.value;
&#125;
//-->
</script>
Post Reply