Subject: adding a class in JavaScript
Posted By: crmpicco Post Date: 10/4/2005 6:02:10 AM

var el = document.getElementById("helpTxtFl_adt");
            
            el.innerHTML = "";
            el.innerHTML = "<font class=font2>"
            for(s=1; s<=segments; s++)
            {
                el.innerHTML = el.innerHTML + document.forms["form"].elements["arrival"+s].value.bold();
                el.innerHTML = el.innerHTML + "&nbsp;to&nbsp;"
                el.innerHTML = el.innerHTML + document.forms["form"].elements["departure"+s].value.bold();
                el.innerHTML = el.innerHTML + "&nbsp;Seat:&nbsp;"
                el.innerHTML = el.innerHTML + passDetails[4];
                if(s != segments)
                {
                    el.innerHTML = el.innerHTML + ",&nbsp;"
                }
                else
                {
                    el.innerHTML = el.innerHTML + "&nbsp;"
                }                
            }
            el.innerHTML = el.innerHTML + "</font>"


Is there any way of attaching a 'class' defined in the CSS to this innerHTML. just adding a font tag is not accepted

www.crmpicco.co.uk
Reply By: joefawcett Reply Date: 10/4/2005 6:08:57 AM
el.className = "<class name here>";


--

Joe
Reply By: crmpicco Reply Date: 10/4/2005 6:17:02 AM
thanks for that Joe:


for(s=1; s<=segments; s++)
            {
                var splitStr = splitString[0];
                eval("passDetails"+s+"") = splitStr.split("/");
            }
            
            el.innerHTML = "";
            el.innerHTML = "<font class=font2>"
            for(s=1; s<=segments; s++)
            {
                el.innerHTML = el.innerHTML + document.forms["form"].elements["arrival"+s].value.bold();
                el.innerHTML = el.innerHTML + "&nbsp;to&nbsp;"
                el.innerHTML = el.innerHTML + document.forms["form"].elements["departure"+s].value.bold();
                el.innerHTML = el.innerHTML + "&nbsp;Seat:&nbsp;"
                el.innerHTML = el.innerHTML + eval("passDetails"+s+"[4]");
                if(s != segments)
                {
                    el.innerHTML = el.innerHTML + ",&nbsp;"
                }
                else
                {
                    el.innerHTML = el.innerHTML + "&nbsp;"
                }                
            }
            el.innerHTML = el.innerHTML + "</font>"


In the code above I keep getting cannot assign errors,
is there a way to name the array dynamically inside the loop
and refer to it dynamically as shown above?

TIA.

Picco

www.crmpicco.co.uk
Reply By: crmpicco Reply Date: 10/4/2005 6:29:54 AM
tried this, but keep getting errors;


var eval("passDetails"+s+"") = splitStr.split("/");



www.crmpicco.co.uk
Reply By: joefawcett Reply Date: 10/4/2005 6:34:24 AM
You know my thoughts on eval, it shouldn't be used. Either use an array or just declare a few variables.

--

Joe
Reply By: crmpicco Reply Date: 10/4/2005 8:15:00 AM
yeah true, i have talken it out all my code. that was my next point - to get rid of eval.
but how could i do it a different way? i'm trying a different way at the mo, will get back to you

www.crmpicco.co.uk

Go to topic 35335

Return to index page 460
Return to index page 459
Return to index page 458
Return to index page 457
Return to index page 456
Return to index page 455
Return to index page 454
Return to index page 453
Return to index page 452
Return to index page 451