Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Are there 'while' loops in javascript? 2

Status
Not open for further replies.

mufka

ISP
Dec 18, 2000
587
US
Is there a way to use a number from HTTP GET to initialize a script multiple times?

I'm using TinyMCE and I have a php script that runs with an incoming variable (number) from another script and I need to initialize TinyMCE the number of times in the variable.

For every text area I want to use, I have to repeat

tinyMCE.init({
mode : "textareas",
theme : "advanced",
});

I tried looping it in PHP but had no luck. I thought maybe javascript could do it. I know nothing about javascript.
 
Sure...
Code:
var i=$yourPHPvariable;
while (i--) {
  tinyMCE.init({
    mode : "textareas",
    theme : "advanced",
  });
}
If PHP has that variable and you're using the PHP script to print this Javascript command to the browser, then just plug in the variable in PHP fashion. If the variable is 5 you get 5 iterations.
 
You're probably looping only the PHP, and not echoing the Javascript that you want written on the page each time through the loop.

Lee
 
It was echoing, but it ended up being a single ' double " issue. In my troubleshooting, I just didn't know if I could echo javascript and have it work. Now I know. Thanks for the input.
 
Ahh what a pain, quotes cause so much trouble =)

If you are just using the PHP loop to duplicate the same call you should probably do the loop in Javascript because all the HTML you generate in PHP has to be sent across the network. It's not a big deal unless that number gets high. On the other hand, leaving the loop implementation in PHP would probably allow you more flexibility if you ever needed to pass those tinyMCE's unique data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top