Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript not working with html doctype?

Status
Not open for further replies.

wvdba

IS-IT--Management
Jun 3, 2008
465
0
0
US
hi,
i have part of a page code:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL] 
...
...
...
...
...
...
<script type="text/javascript">
     function myfunction()
     {
       alert("inside the function");               
       var xxx;
       xxx = form1.field.value; 
       alert(xxx);
     }
</script>
when i take out doctype, it recognizes my form1.field.value
but when i put it back, the value of form1.field.value is undefined.
 
Try to use document.getElementById function instead. I'd also maybe consider asking in the js forum if that doesn't work as it may be an issue with the name "field".

[!]
-------------------------------------------------------

Mark,

Join me at the new IT Community of the 21st Century: [!][URL unfurl="true"]http://lessthandot.com[/!][/url]

[/!]
 
1. What is "form1"? You should probably use "document.forms['form1']" instead.

2. Try "document.forms['form1'].elements['field'].value"

But as Mark says, forum216 is probably a better place to ask if it turns out to be a JS issue.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
You cand either use external JavaScript files or use CDATA sections in XHTML:
Code:
 <script type="text/javascript" src="/script/site.js"></script>
Code:
<script type="text/javascript">
<![CDATA[
... unescaped script content ...
]]>
</script>

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
thanks everybody.
i'm going to try the suggestions.
 
thanks billyray,
this line that you posted, worked ok.
"document.forms['form1'].elements['field'].value"
however, i'm having problem trying to make that fit a drop-down/select item value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top