[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 05-15-2007, 01:57 AM   #1 (permalink)
Senior Member
 
champ_rock's Avatar
 
Join Date: Oct 2006
Location: http://akshayjain.org
Posts: 2,768
8,037.05 NP$ (Donate)

champ_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond repute


help with html+php

hi

as always please tell me what am i doing wrong in this?

Code:
<?php

$list = file('list.txt');
srand((float)microtime() * 1000000);
shuffle($list);

echo '<html><br><select multiple name="crap" size="10">';

foreach ($list as $url) {
$u= "<option value='$url' onclick=\"window.location='$url'\"><b>$url</b></option>";
echo $u;
}
echo '</select>';
?>
out put of this http://www.champrock.uk.to/demo/list.php

this outputs the html code as
Code:
<html><br><select multiple name="crap" size="10"><option value='http://mail.yahoo.com
' onclick="window.location='http://mail.yahoo.com
'"><b>http://mail.yahoo.com
</b></option><option value='http://gmail.com
' onclick="window.location='http://gmail.com
'"><b>http://gmail.com
</b></option><option value='http://yahoo.com
' onclick="window.location='http://yahoo.com
'"><b>http://yahoo.com
</b></option><option value='http://airb.us.to
' onclick="window.location='http://airb.us.to
'"><b>http://airb.us.to
</b></option><option value='http://google.com
' onclick="window.location='http://google.com
'"><b>http://google.com
</b></option></select>
if i rearrange this code properly and run it as a html file then it works fine.

therefore i guess the problem is with these arrangement and the new lines that are being created before ' onclick




thanks
__________________
Akshay Jain
......................

Last edited by champ_rock; 05-15-2007 at 02:10 AM.
champ_rock is offline  
Old 05-15-2007, 03:04 AM   #2 (permalink)
NamePros Regular
 
Join Date: Mar 2005
Posts: 412
162.25 NP$ (Donate)

paaaaaaaaaa is a jewel in the roughpaaaaaaaaaa is a jewel in the roughpaaaaaaaaaa is a jewel in the rough


those line breaks are breaking the javascript. In your text file don't have the list on new lines or remove line breaks with some php. You could separate each value with a comma and then use implode/explode. Or you could use a string replace to remove line breaks in each url value.
__________________
Please add to my rep points if i was helpful. Thanks.

Ripe Website Manager - Steve Parish
paaaaaaaaaa is offline  
Old 05-15-2007, 03:31 AM   #3 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future

Autism Autism Autism Autism Autism Autism Autism
Add
$url = trim($url);

After
foreach ($list as $url) {
Dan is offline  
Old 05-15-2007, 04:48 AM   #4 (permalink)
Senior Member
 
champ_rock's Avatar
 
Join Date: Oct 2006
Location: http://akshayjain.org
Posts: 2,768
8,037.05 NP$ (Donate)

champ_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond repute


thanks guys this trim() works..

also, please tell me how do i open it in a new window on being clicked?

one more thing, i am feeling that i am miserable in php. do u think i should even think about continuing it? every script it create has some bug which i have to get sorted here by your help.
__________________
Akshay Jain
......................
champ_rock is offline  
Old 05-15-2007, 03:10 PM   #5 (permalink)
cef
NamePros Regular
 
Join Date: May 2004
Location: NYC
Posts: 236
76.50 NP$ (Donate)

cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough

Animal Rescue
Quote:
Originally Posted by champ_rock
thanks guys this trim() works..

also, please tell me how do i open it in a new window on being clicked?
In your "onclick" code, instead of
PHP Code:
window.location='$url'
use
PHP Code:
window.open('$url');
Quote:
one more thing, i am feeling that i am miserable in php. do u think i should even think about continuing it? every script it create has some bug which i have to get sorted here by your help.
Ah, keep going I've been doing this for years (decades actually) and I still keep the manual open because I never remember things like the parameter order to str_replace()

Like anything, it gets easier over time. But I know how frustrating it is when just starting out with a new language.

Besides, it seems like you have a head for this stuff, so don't give up; just keep having fun and asking questions.
cef is offline  
Old 05-15-2007, 03:16 PM   #6 (permalink)
Barru.
 
Barrucadu's Avatar
 
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,731
78.50 NP$ (Donate)

Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold


Keep at it, all languages seem hard at first (though I would rather learn another programming language than do my french gcse, yikes!)

Quote:
Originally Posted by cef
I still keep the manual open because I never remember things like the parameter order to str_replace()
Good to know i'm not the only one who forgets parameter order in common functions.
Barrucadu is offline  
Old 05-15-2007, 04:26 PM   #7 (permalink)
cef
NamePros Regular
 
Join Date: May 2004
Location: NYC
Posts: 236
76.50 NP$ (Donate)

cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough

Animal Rescue
Yeah, the dirty little secret of our industry, eh?
cef is offline  
Old 05-16-2007, 08:06 AM   #8 (permalink)
NamePros Member
 
Join Date: Apr 2005
Posts: 116
134.00 NP$ (Donate)

mikesherov will become famous soon enoughmikesherov will become famous soon enough


parameter order was an issue until I started using a IDE that did code completion... it pops up the parameter order as soon as I type the first "(" in "str_replace("...

gone are the days of memorizing "search,replace,subject"
mikesherov is offline  
Old 05-17-2007, 12:31 AM   #9 (permalink)
Senior Member
 
champ_rock's Avatar
 
Join Date: Oct 2006
Location: http://akshayjain.org
Posts: 2,768
8,037.05 NP$ (Donate)

champ_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond repute


Code:
 window.open('$url');
this does not work please check at http://www.champrock.uk.to/demo/list.php
__________________
Akshay Jain
......................
champ_rock is offline  
Old 05-17-2007, 01:07 AM   #10 (permalink)
cef
NamePros Regular
 
Join Date: May 2004
Location: NYC
Posts: 236
76.50 NP$ (Donate)

cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough

Animal Rescue
Quote:
Originally Posted by champ_rock
Code:
 window.open('$url');
this does not work please check at http://www.champrock.uk.to/demo/list.php
If you look at the source for your page in the browser, you'll see lines like:

Code:
onclick="window.open='http://gmail.com'"
Which is invalid Javascript syntax. It should look like

Code:
onclick="window.open('http://gmail.com');"
You need to fix the php code which is generating the statements.
cef is offline  
Old 05-17-2007, 01:11 AM   #11 (permalink)
Senior Member
 
champ_rock's Avatar
 
Join Date: Oct 2006
Location: http://akshayjain.org
Posts: 2,768
8,037.05 NP$ (Donate)

champ_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond repute


well please check the syntax now.. i think i have rectified it

the php code is
Code:
	$u= "<option value='$url' onclick=\"window.open=('$url')\"><b>$url</b></option>";
.

but it still does not work
__________________
Akshay Jain
......................
champ_rock is offline  
Old 05-17-2007, 07:30 AM   #12 (permalink)
cef
NamePros Regular
 
Join Date: May 2004
Location: NYC
Posts: 236
76.50 NP$ (Donate)

cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough

Animal Rescue
It's still wrong There's an extra = sign in there. It should be

Code:
	$u= "<option value='$url' onclick=\"window.open('$url')\"><b>$url</b></option>";
cef is offline  
Old 05-17-2007, 08:03 AM   #13 (permalink)
Senior Member
 
champ_rock's Avatar
 
Join Date: Oct 2006
Location: http://akshayjain.org
Posts: 2,768
8,037.05 NP$ (Donate)

champ_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond repute


thanks dude it works..

its tough to debug ur own code. i compared those two code lines and i could not find the difference until the third time
__________________
Akshay Jain
......................
champ_rock is offline  
Old 05-17-2007, 03:23 PM   #14 (permalink)
cef
NamePros Regular
 
Join Date: May 2004
Location: NYC
Posts: 236
76.50 NP$ (Donate)

cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough

Animal Rescue
It happens; sometimes your eyes do one thing and your brain another

Glad it worked out.
cef is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 02:07 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85