Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 4th, 2005, 06:02 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
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
Reply With Quote
  #2 (permalink)  
Old October 4th, 2005, 06:08 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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

Joe
Reply With Quote
  #3 (permalink)  
Old October 4th, 2005, 06:17 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
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
Reply With Quote
  #4 (permalink)  
Old October 4th, 2005, 06:29 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
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
Reply With Quote
  #5 (permalink)  
Old October 4th, 2005, 06:34 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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
Reply With Quote
  #6 (permalink)  
Old October 4th, 2005, 08:15 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:27 PM.


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