| | |
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
![]() |
•
•
Join Date: Nov 2007
Posts: 12
Reputation:
Solved Threads: 0
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
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
Hi,
try this instead:
try this instead:
javascript Syntax (Toggle Plain Text)
<!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>
Last edited by essential; Aug 21st, 2009 at 11:47 am. Reason: Typo
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
![]() |
Similar Threads
- JavaScript link not working in Firefox (JavaScript / DHTML / AJAX)
- google sitelinks question (Search Engine Optimization)
- Javascript Firefox Help (JavaScript / DHTML / AJAX)
- disable javascript through javascript in firefox (JavaScript / DHTML / AJAX)
- Javascript and Firefox ISSUES (JavaScript / DHTML / AJAX)
- Need JavaScript/Firefox HELP (JSP)
- Can't view JavaScript on Firefox/IE (Web Browsers)
- hover over text tips (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Menu in bottom bar
- Next Thread: Object required error
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array browser bug captchaformproblem cart checkbox child class close codes createrange() css cursor date debugger decimal dependent design disablefirebug dom dropdown editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post problem programming progressbar prototype redirect runtime safari scale scriptlets scroll search security shopping size software toggle unicode w3c web wysiwyg \n





