954,160 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

retrieving alt attribute using javascript in firefox

Dear Friends,
we are facing a problem with alt attribute in Java script.While retrieving alt attribute in IE its working fine but in FireFox we are getting as undefined.Please give solution for retrieving the alt attribute in firefox.

please find the below code for how i am retrieving...



sivakumarl
Newbie Poster
17 posts since Nov 2007
Reputation Points: 8
Solved Threads: 0
 

Hi,

try this instead:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>www.daniweb.com</title>
<script type="text/javascript">
<!--
var d = document;
window.onload = function() {
var els = ( "testform" in d ) ? d.testform : d.getElementById( "testform" );
var attr = [ "id", "title", "alt" ];
   if ( els ) { 
      els = els["testing"];
      var col = "\n";
      for ( var i = 0; i < attr.length; i++ ) {
         if ( els.getAttribute( attr[ i ] )) {
            col += attr[ i ] + " : " + els.getAttribute( attr[ i ] ) + "\n";
            continue;
         }
      } return alert( col );
   } alert( "Unsupported script, please update your browser" );
   return false
}
// -->
</script>
</head>
<body>
<div>
<form id="testform" name="testform" action="#" onsubmit="return false;">
<div>
<!-- Using ( ALT ) Attribute in a select tag is NOT RECOMMENDED in any of the W3C Standard (x)HTML document templates'.

This document will output 1 error: ( Attribute "ALT" is not a valid attribute ) -

and will not validate, if you will attempt to verify these document with W3C markup validation tool.
-->

<select id="testing" name="testing" alt="test|001" title="test|ddd" size="1">
<option value="alt attribute">ALT Attribute</option>
</select>
</div>
</form>
</div>
</body>
 </html>
essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

Hi essential,

Thanks for your reply.
This code really helps :)

sivakumarl
Newbie Poster
17 posts since Nov 2007
Reputation Points: 8
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You