retrieving alt attribute using javascript in firefox

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Nov 2007
Posts: 12
Reputation: sivakumarl is an unknown quantity at this point 
Solved Threads: 0
sivakumarl sivakumarl is offline Offline
Newbie Poster

retrieving alt attribute using javascript in firefox

 
0
  #1
Aug 21st, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: retrieving alt attribute using javascript in firefox

 
0
  #2
Aug 21st, 2009
Hi,

try this instead:
  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
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 12
Reputation: sivakumarl is an unknown quantity at this point 
Solved Threads: 0
sivakumarl sivakumarl is offline Offline
Newbie Poster

Re: retrieving alt attribute using javascript in firefox

 
0
  #3
Aug 21st, 2009
Hi essential,

Thanks for your reply.
This code really helps
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC