Mithrand1r
Mithrand1r

Reputation: 2353

JS & HTML post different table dependand of browser version

I have problem with creating dynamic table which will work in Internet Explorer 6 because of json usage. I actually found nice work around. I want to implement script which will show different html table depends on version of the user browser.
Here is my browser version detector script:

<script>
    function getInternetExplorerVersion()
    // Returns the version of Windows Internet Explorer or a -1
    // (indicating the use of another browser).
    {
        var rv = -1; // Return value assumes failure.
        if (navigator.appName == 'Microsoft Internet Explorer'){
            var ua = navigator.userAgent;
            var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
            if (re.exec(ua) != null)
                rv = parseFloat( RegExp.$1 );
        }
        return rv;
    }
function checkIEVersion()
{
   var ver = getInternetExplorerVersion();
   if ( ver> -1 )
   {
      if ( ver == 6.0 ){
    <? echo"<TABLE id=\"tableToModify\" width=\"1100px\" border=\"1\"  class='list questionaire' width='600'>";
    echo" <TR class='columndesc'>";
    echo"<TD WIDTH=\"50%\">Col1<font color=\"red\">*</font></TD>";
    echo"<TD WIDTH=\"50%\">Col1<font color=\"red\">*</font></TD>";

    echo  "</TABLE>";   ?>     
   }
    echo"<TABLE id=\"tableToModify\" width=\"1100px\" border=\"1\"  class='list questionaire' width='600'>";
    echo" <TR class='columndesc'>";
    echo"<TD WIDTH=\"22%\">Col1<font color=\"red\">*</font></TD>";
    echo"<TD WIDTH=\"22%\">col2<font color=\"red\"></font></TD>";
    echo"<TD WIDTH=\"22%\">col3<font color=\"red\"></font></TD>";
    echo"<TD WIDTH=\"22%\">col4<font color=\"red\">*</font></TD>";
    echo" <TD WIDTH=\"22%\">col5<font color=\"red\">*</font></TD>";
    echo" <TD WIDTH=\"12%\"> col6<font color=\"red\">*</font></TD>";
    echo  "</TABLE>";

?>
}
}
checkIEVersion();
</script>

But right now I am getting errorz : uncaught syntax exception. I do realise that php - echo is the couse but I can't come with another idea especially when I want this table to be showed in the position I want it to be:



Some html fields, imput tables buttons forms


Script I posted above


other form fields etc

to summarize I have HTML code above and under the script.
Can anyone give me a hint how to fix my problem?

Upvotes: 0

Views: 78

Answers (1)

silentw
silentw

Reputation: 4885

I believe this is what you need (might need tweaking according to your needs):

function getInternetExplorerVersion()
// Returns the version of Windows Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null) rv = parseFloat(RegExp.$1);
    }
    return rv;
}

function checkIEVersion() {
    var ver = getInternetExplorerVersion();
    if (ver > -1) {
        if (ver == 6.0) {
            $html = "<TABLE id=\"tableToModify\" width=\"1100px\" border=\"1\"  class='list questionaire' width='600'>" +
            "<TR class='columndesc'>" +
            "<TD WIDTH=\"50%\">Col1<font color=\"red\">*</font></TD>" +
            "<TD WIDTH=\"50%\">Col1<font color=\"red\">*</font></TD>" +
            "</TABLE>";
        } else {
            $html = "<TABLE id=\"tableToModify\" width=\"1100px\" border=\"1\"  class='list questionaire' width='600'>" +
            "<TR class='columndesc'>" +
            "<TD WIDTH=\"22%\">Col1<font color=\"red\">*</font></TD>" +
            "<TD WIDTH=\"22%\">col2<font color=\"red\"></font></TD>" +
            "<TD WIDTH=\"22%\">col3<font color=\"red\"></font></TD>" +
            "<TD WIDTH=\"22%\">col4<font color=\"red\">*</font></TD>" +
            "<TD WIDTH=\"22%\">col5<font color=\"red\">*</font></TD>" +
            "<TD WIDTH=\"12%\"> col6<font color=\"red\">*</font></TD>" +
            "</TABLE>";
        }
        document.write($html);
    }
}
checkIEVersion();

Upvotes: 3

Related Questions