943,712 Members | Top Members by Rank

Ad:
Aug 21st, 2009
0

retrieving alt attribute using javascript in firefox

Expand Post »
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...
<html>
<head>
<script type="text/javascript">

window.onload = function()
{


var els= document.forms[0].elements;
var compcode ="";
for(var i= 0; i < els.length; i++)
{
if (els[i].id!="")
{
alert(els[i].id);
alert(els[i].title);
alert(els[i].alt);
}

}
}

</script>
</head>
<form action="#">
<select name="test" id="testing" alt="test|001" title="test|ddd">
</select>
</form>
</html>

The above code is working fine in IE but not in firefox

Cheers
----------
Siva kumar
Similar Threads
Reputation Points: 8
Solved Threads: 0
Newbie Poster
sivakumarl is offline Offline
17 posts
since Nov 2007
Aug 21st, 2009
0

Re: retrieving alt attribute using javascript in firefox

Hi,

try this instead:
javascript Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta http-equiv="Content-Script-Type" content="text/javascript">
  7. <title>www.daniweb.com</title>
  8. <script type="text/javascript">
  9. <!--
  10. var d = document;
  11. window.onload = function() {
  12. var els = ( "testform" in d ) ? d.testform : d.getElementById( "testform" );
  13. var attr = [ "id", "title", "alt" ];
  14. if ( els ) {
  15. els = els["testing"];
  16. var col = "\n";
  17. for ( var i = 0; i < attr.length; i++ ) {
  18. if ( els.getAttribute( attr[ i ] )) {
  19. col += attr[ i ] + " : " + els.getAttribute( attr[ i ] ) + "\n";
  20. continue;
  21. }
  22. } return alert( col );
  23. } alert( "Unsupported script, please update your browser" );
  24. return false
  25. }
  26. // -->
  27. </script>
  28. </head>
  29. <body>
  30. <div>
  31. <form id="testform" name="testform" action="#" onsubmit="return false;">
  32. <div>
  33. <!-- Using ( ALT ) Attribute in a select tag is NOT RECOMMENDED in any of the W3C Standard (x)HTML document templates'.
  34.  
  35. This document will output 1 error: ( Attribute "ALT" is not a valid attribute ) -
  36.  
  37. and will not validate, if you will attempt to verify these document with W3C markup validation tool.
  38. -->
  39.  
  40. <select id="testing" name="testing" alt="test|001" title="test|ddd" size="1">
  41. <option value="alt attribute">ALT Attribute</option>
  42. </select>
  43. </div>
  44. </form>
  45. </div>
  46. </body>
  47. </html>
  48.  
Last edited by essential; Aug 21st, 2009 at 11:47 am. Reason: Typo
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Aug 21st, 2009
0

Re: retrieving alt attribute using javascript in firefox

Hi essential,

Thanks for your reply.
This code really helps
Reputation Points: 8
Solved Threads: 0
Newbie Poster
sivakumarl is offline Offline
17 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Menu in bottom bar
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Object required error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC