oakleymk 0 Newbie Poster

Using <script language="JavaScript" src="javascript.js" type="text/javascript"/> is not valid (as per the W3C) for 2 reasons. The first being that the script tag is a content element and must use a </script> to close the elements envelope. The second, if the script tag was a leaf (contentless) element, there must contain a space before the /> . Using language="JavaScript" has been deprecated.

The only exception to this is when using XHTML, and although using the script tag as a leaf element will parse correctly in most modern browsers, it will cause the page to break in older browsers. This lack of backward compatibility is the primary reason the W3C will ONLY validate the script tag as a leaf element when used in XHTML.

To prove this point, I have provided a srcipt tag test using standard HTML and a srcipt tag test using XHTML. The official W3C validator can be found at validator.w3.org site.

Lastly, your in page script must use type="text/javascript" to validate correctly. Again, using language="JavaScript" has been deprecated and is not necessary.

Hope this helps. Enjoy! :)

oakleymk 0 Newbie Poster

I have noticed that there is no longer a help page in the FAQ on how to use [TAGS] in the editor. Can we please get a help button? Maybe after the check spelling button?

It would be helpful if the help included best-practices and examples :)

oakleymk 0 Newbie Poster

The only way to access that object without [] would be to give it an id/name or path to it using a node reference such as ...nextSibling from an object you are able to reference.

I would suggest working this problem from another angel and find a way to access the page through another medium. Even if you do solve the immediate, JavaScript relies heavily on arrayed objects and you will likely end up with the same problem all over again.

Best of luck :)

oakleymk 0 Newbie Poster

Hello,

First, I want to say that you can type [ and ] on the iPhone though I did see that people where having problems typing brackets in some terminal applications.

Second, square brackets are a core component in JavaScript, despite the fact that I was able to create a function for you, you will run into many problems not being able to use them.

Here is the script:

<script type="text/javascript"><!--//

// set your array
var a = new Array("dog","cat","bird")

// prototype function to access the array
Array.prototype.getArrayNum=function(num){var val=this.toString()+",";for(var i=0;i<num;i++){val=val.substring(val.indexOf(",")+1)}return val.substring(0,val.indexOf(","))}


// just type the number of the array element you want 
alert(a.getArrayNum(3))



//--></script>

Enjoy! :)

oakleymk 0 Newbie Poster

Thank you for your comments they are much appreciated.

With respect to your viewpoint with treating the page as a scroll, I agree that this is how most development is done. I have been designing web pages since the late 90’s and have watched the evolution of browsers. Browsers have slowly become a portal of how we interact in our society. This evolution has only been possible because of standards that have been implemented to allow for greater control of its environment. In my professional observation, the limitations often occur only when the standards are not followed.

As the use of browsers have advanced beyond simple webpages and more toward web based applications, a greater level of precision is required to deliver dynamic content. If we all had succumbed to the idea of “oh… it was never designed for that” we would never of had the advent of AJAX, .NET, and many other recent web based technologies. As I have demonstrated in my post, most browsers adhere to some level of the W3C standards these days, though as my post clearly shows, some browsers do have shortcomings.

Contrary to your statement, I have a library of functions that do exactly what you state browsers weren’t designed to do, and I have been doing it for many years. My efforts recently have migrated toward updating these functions to be more cross-browser/cross-doctype compactable by taking advantage of XHTML. I have nearly completed the new set of functions and as …

oakleymk 0 Newbie Poster

Hello,

First let me start with the fact that JavaScript is a human language designed to give instructions to an application. As such, it should be used in a manner that is easy for people to read. Proper formatting is critical to allowing people to understand the instructions so that errors are not made that would cause the application to fail the execution of the script. That said, I found that in function checkform() you placed too many end brackets and is the most logical cause of the script failing.

I have taken the time to cleanup your code. However, without the html part of your page it is impossible to do any further troubleshooting. I would strongly suggest using an editor that is designed to help people work with code like Notepad++. Here is the cleaned up code:

function handler(where){ //check for unusual characters
  var iChars="!@#$%^&*()+=-[]\\\';,./{}|\":<>?",wspace = " ";
  for(var i=0;i<where.value.length;i++){
    if(iChars.indexOf(where.value.charAt(i))!=-1){return false}
    if(wspace.indexOf(where.value.charAt(i))!=-1){return "nope"}
  }
} 


function emailhandler(where){ //check for unusual characters
  var iChars = "!#$%^&*()+=-[]\\\';,/{}|\":<>?",wspace = " ";
  for(var i = 0; i < where.value.length; i++){
    if(iChars.indexOf(where.value.charAt(i)) != -1){return false}
    if(wspace.indexOf(where.value.charAt(i)) != -1){return "nope"}
  }
}


function isNumberKey(evt,where){
  var charCode=(evt.which)?evt.which:event.keyCode;
  if(charCode!=8){
    var count=where.value.length; 
    if(count===0){where.value="("}
    if(count==4){where.value+=")"}
    if(count==8){where.value+="-"}
    if(charCode>31&&(charCode<48||charCode>57)){return false}
    else{return true}
  }
  else{return true}
}


function checkform(){
  var mycount=document.getElementsByTagName("input").length;
  var good=true;
  for(i=0;i<=mycount;i++){

    //alert(document.getElementsByTagName("input")[i].id);

    var current=document.getElementsByTagName('input')[i];
    current.style.border="1px solid"; 

    //check email
    if(current.id=="email"){
      if(current.value!==""){
        var test=emailhandler(current);
        if(test=="nope"){
          alert("Your Email Address can not contain spaces!");
          //good=false;
        }
        if(test===false){
          alert("Your Email Address can not contain special characters!");
          //good=false; …
oakleymk 0 Newbie Poster

That is a good way to handle it if you are wanting to insert an <img /> tag. A faster rendering method would be to place the image tag directly next to the input field like so:

<input id="passField" name="passField" type="text" /><img id="passFieldImg" src="blankimg.gif" />

You can then change the image in your validation function using:

if( /*PASS CONDITION*/ ){
  document.getElementById('passFieldImg').src="pass.gif"
}
else{
  document.getElementById('passFieldImg').src="fail.gif"
}
oakleymk 0 Newbie Poster

Hello,

OK... at first glance, the problem is that the calculate function is only working under 2 conditions, the first document.layers for old Netscape, and the second document.all for Internet Explorer.

I’m not seeing anything in the document.all section that appears to be IE specific.

Try changeing the if (document.all){ to else{ .

I this fails to work let me know and I will take a closer look at it.

oakleymk 0 Newbie Poster

Hi All,
This is the parent issue that led to the post Need help with getDOCTYPE() function (http://www.daniweb.com/forums/thread196837.html)

USING THE BODY METHOD: The following code will properly get the viewable window area if no DOCTYPE is specified. document.getElementsByTagName("body")[0].clientWidth//Height OR document.body.clientWidth//Height If DOCTYPE is XHTML ANY* the above code reports only the defined page area as if it was a wraper**.

USING THE HTML METHOD: The following code will properly get the viewable window area when DOCTYPE XHTML ANY* is used. document.getElementsByTagName("html")[0].clientWidth//Height OR document.documentElement.clientWidth//Height If no DOCTYPE is used the above code reports only the defined page area as if it was a wrapper**, EXCEPT IE6+ (not tested in older browsers) reports 0.

-----

So the problem here is how to create a cross-doctype compatible function for getting the width & height of the window/frame. I have played with several methods but each produced problems. The best solution I can think of is to detect the doctype by using the following code:

FireFox3, Safari and Chrome*** work according to the W3C standard document.doctype using .publicId & .systemId , but this causes IE to get a hard error. IE will however allow reference to the DOCTYPE through node objects. Both document.body.parentNode.parentNode.firstChild.nodeValue and document.getElementsByTagName("!")[0].nodeValue work in IE but not other browsers. So I came up with a function to tackle this issue:

function getDOCTYPE(){
  var pid,sid,val,lng,ver,typ;
  try{
    pid=String(document.doctype.publicId);
    sid=String(document.doctype.systemId);
  }
  catch(err){
    val=String(document.body.parentNode.parentNode.firstChild.nodeValue)
    pid=val.replace(/^[^\"]*\"([^\"]+)\".*/,"$1");
    sid=((/http/).test(val))?val.replace(/^.*\"\s\"(http.*)/,"$1"):null
  }

  lng=((/xhtml/i).test(pid+sid))?"XHTML":"HTML";
  typ=((/strict/i).test(pid+sid))?"Strict":((/trans|loose/i).test(pid+sid))?"Transitional":((/frame/i).test(pid+sid))?"Frameset":((/basic/i).test(pid+sid))?"Basic":((/mobile/i).test(pid+sid))?"Mobile":null;
  ver=((/html\s*\d+\.?\d*/i).test(pid))?pid.replace(/^.*html\s*(\d+\.?\d*)\D*/i,"$1"):null;

  return {publicId:pid,systemId:sid,language:lng,type:typ,version:ver,set:lng+" "+typ+" "+ver}
}

As …

oakleymk 0 Newbie Poster

in javascript it would be done this way if someone would like to translate it to php

var a="bob";
var b="joe";

a=[a,b];b=a[0];a=a[1];

enjoy! :)

oakleymk 0 Newbie Poster

Hello,

wasn't sure if you where aware that filters.blendTrans only works in IE...

the better way to handle this for cross-browser support is by using DOM .opacity If I can find some time over the next few days i will put a sample together for you.

oakleymk 0 Newbie Poster

By the way,
Chrome only works when using

<meta name="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
oakleymk 0 Newbie Poster

To simplify the issue:
alert(document.body.parentNode.parentNode.firstChild.nodeValue) //does not seem to properly refrence the doctype node
// I have tried many other node paths and have had no luck accessing the doctype :(
alert(document.getElementsByTagName("!")[0].nodeValue) // I just stumbled across this trying different methods.

alert(document.doctype.publicId) //seems to be unsupported even though all references I have state that it is supported in XML and XHTML (for Opera)

oakleymk 0 Newbie Poster

Hi All,

Without getting into too much history on the why, I came into a situation where I needed to create a function to get various properties of !DOCTYPE so that other functions could adjust to work properly with certain DOCTYPEs (Strict, Transitional, etc.). I have tested the function in the following Windows browsers IE6+ FF3+ Chrome2+ and Safari3+ Opera9+. The only one that I can’t get working is Opera (testing with 9.64). I’m hoping that someone out that has a solution! Here is the code:

function getDOCTYPE(loc){
  loc=locEval(loc)||self; // locEval is a function i use to qualify window/frame paths
  var pid,sid,val,lng,ver,typ;

  try{ // this is the node model that should be supported by all browsers. IE gets a hard error with it though.
    pid=String(loc.document.doctype.publicId);
    sid=String(loc.document.doctype.systemId);
  }
  catch(err){
    val=String(loc.document.body.parentNode.parentNode.firstChild.nodeValue) // seems to only work in IE
    //val=document.getElementsByTagName("!")[0].nodeValue  // works in IE as well

    pid=val.replace(/^[^\"]*\"([^\"]+)\".*/,"$1");
    sid=((/http/).test(val))?val.replace(/^.*\"\s\"(http.*)/,"$1"):null
  }

  lng=((/xhtml/i).test(pid+sid))?"XHTML":"HTML";
  typ=((/strict/i).test(pid+sid))?"Strict": ((/trans|loose/i).test(pid+sid))?"Transitional": ((/frame/i).test(pid+sid))?"Frameset": ((/basic/i).test(pid+sid))?"Basic": ((/mobile/i).test(pid+sid))?"Mobile": null;
  ver=((/html\s*\d+\.?\d*/i).test(pid))?pid.replace(/^.*html\s*(\d+\.?\d*)\D*/i,"$1"):null;

  return {publicId:pid,systemId:sid,language:lng,type:typ,version:ver,dtd:lng+" "+typ+" "+ver}
}

//...

alert(getDOCTYPE().dtd)

Any help would be greatly appreciated! :)