Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old June 5th, 2003, 06:06 AM
tansan tansan is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 15 tansan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
string variable not working

hi!

need help to resolve this...

i'm doing a popup menu in javascript and php. i noticed that if i do a

php Code:
Original - php Code
  1.  
  2. <script language="Javascript">
  3.   x = computer;
  4.   category.addMenuItem(x)
  5. </script>


then the x is added to the menu, but everytime i do

php Code:
Original - php Code
  1.  
  2. <script language="Javascript">
  3.   x = <?php echo $row['prod_category'] ?>;
  4.   category.addMenuItem(x)
  5. </script>


then nothing happens.
php Code:
Original - php Code
  1. <?php echo $row['prod_category'] ?>
returns a value of 'computer', though. note that 'category' is a class object.

any idea here?

thanks!

Reply With Quote
  #2  
Old June 5th, 2003, 07:20 AM
crisp crisp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Holland
Posts: 336 crisp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: string variable not working

Like in PHP strings should be enclosed between quotes:

<script type="text/javascript" language="Javascript">
x = '<?php echo $row['prod_category'] ?>';
category.addMenuItem(x);
</script>

Reply With Quote
  #3  
Old June 5th, 2003, 08:41 AM
tansan tansan is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 15 tansan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: string variable not working

thanks crisp!

by the way, sorry for not emphasizing this in my previous post but doing a

x = 'computer'

doesn't work either so it seems that assigning the variable x with a string value causes the object category not to accept x. and perhaps javascript treats <?php echo $row['prod_category'] ?> as string. this is what i actually mean in this post's title...


Reply With Quote
  #4  
Old June 5th, 2003, 10:01 AM
crisp crisp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Holland
Posts: 336 crisp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: string variable not working

javascript will only treat a value as string when it is enclosed in quotes. Else it will treat it as a number or an object reference.
The fact that you write your script with PHP shouldn't matter, what matters is what is sent to the browser, which you can easily see by using view-source in your browserscreen.

Could you post some more of this script? I would assume that you need to sent a string to your addMenuItem method..

Reply With Quote
  #5  
Old June 5th, 2003, 11:03 AM
tansan tansan is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 15 tansan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: string variable not working

here's the code. it's a bit long:

php Code:
Original - php Code
  1.  
  2. <head>
  3. <title>Document1</title>
  4. <script language="JavaScript">
  5. function mmLoadMenus() {
  6.     if (window.category) return;       
  7.    
  8.     <!-- create objects for categories. database driven
  9.     <?php while ($rowCategory = $rsCategory->fetchRow()) { ?>      
  10.         var cat = '<?php echo $rowCategory[1] ?>';
  11.         window.cat = new Menu("cat",0,17,"Verdana, Arial, Helvetica, sans-serif",11,"#000000","#FFFFFF","#CCCCCC","#000084","left","middle",3,0,1000,-5,7,true,true,true,0,true,true)
  12.       <!-- place submenus. should be database driven also      
  13.         cat.addMenuItem(subcat1);
  14.         cat.addMenuItem(subcat2);      
  15.     <?php } ?>
  16.    
  17.     <!-- create the root menu
  18.     window.category = new Menu("root",0,17,"Verdana, Arial, Helvetica, sans-serif",11,"#000000","#FFFFFF","#CCCCCC","#000084","left","middle",3,0,1000,-5,7,true,true,true,0,true,true);
  19.  
  20.     <!-- populate the root menu with created objects above. database driven
  21.     <?php while ($rowCategory = $rsCategory->fetchRow()) { ?> 
  22.         var i = '<?php echo $rowCategory[1] ?>';    
  23.         category.addMenuItem(i);   
  24.     <?php } ?>
  25.     category.writeMenus();
  26. }
  27. </script>
  28. <script language="JavaScript" src="mm_menu.js"></script>
  29. </head>


i manually coded the the script then use the data from dbase and it ran properly. i just notice that doing a category.addMenuItem(prod1); works fine but category.addMenuItem("prod1"); didn't.

Reply With Quote
  #6  
Old June 5th, 2003, 12:38 PM
crisp crisp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Holland
Posts: 336 crisp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: string variable not working

try changing

var i = '<?php echo $rowCategory[1] ?>';
category.addMenuItem(i);

into

category.addMenuItem(<?php echo $rowCategory[1] ?>);

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > string variable not working


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Try It Free




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway