Help with html+php

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch
Impact
91
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
 
Last edited:
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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.
 
0
Close
Add
$url = trim($url);

After
foreach ($list as $url) {
 
0
Close
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.
 
0
Close
champ_rock said:
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:
window.location='$url'

use
PHP:
window.open('$url');

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.
 
0
Close
Keep at it, all languages seem hard at first (though I would rather learn another programming language than do my french gcse, yikes!)

cef said:
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.
 
0
Close
Yeah, the dirty little secret of our industry, eh?
 
0
Close
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"
 
0
Close
0
Close
champ_rock said:
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.
 
0
Close
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
 
0
Close
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>";
 
0
Close
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 :(
 
0
Close
It happens; sometimes your eyes do one thing and your brain another :tri:

Glad it worked out.
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back