Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2005, 06:02 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default adding a class in JavaScript

Code:
var el = document.getElementById("helpTxtFl_adt");

            el.innerHTML = "";
            el.innerHTML = ""
            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 + ""
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
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old October 4th, 2005, 06:08 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Code:
el.className = "<class name here>";
--

Joe
 
Old October 4th, 2005, 06:17 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

thanks for that Joe:

Code:
for(s=1; s<=segments; s++)
            {
                var splitStr = splitString[0];
                eval("passDetails"+s+"") = splitStr.split("/");
            }

            el.innerHTML = "";
            el.innerHTML = ""
            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 + ""
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
 
Old October 4th, 2005, 06:29 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

tried this, but keep getting errors;

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

www.crmpicco.co.uk
 
Old October 4th, 2005, 06:34 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You know my thoughts on eval, it shouldn't be used. Either use an array or just declare a few variables.

--

Joe
 
Old October 4th, 2005, 08:15 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
access internal class by adding namespace shubhanker_techgeek General .NET 0 November 24th, 2008 08:49 AM
Adding to a class library using the List..Add BigJay86 C# 2 June 23rd, 2006 04:08 PM
Adding javascript to popups chrscote Javascript How-To 2 June 8th, 2005 04:34 AM
Adding functionality to the String class? RobMeade BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 5 February 9th, 2005 02:11 PM
Adding Page_Load to base class doesn't work Raeldor BOOK: ASP.NET Website Programming Problem-Design-Solution 2 September 24th, 2004 06:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.