| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Senior Member | 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>';
?>
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> therefore i guess the problem is with these arrangement and the new lines that are being created before ' onclick thanks Last edited by champ_rock; 05-15-2007 at 02:10 AM. |
| |
| | #2 (permalink) |
| NamePros Regular | 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 |
| |
| | #4 (permalink) |
| Senior Member | 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. |
| |
| | #5 (permalink) | ||
| NamePros Regular | Quote:
PHP Code: PHP Code: Quote:
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. | ||
| |
| | #6 (permalink) | |
| Barru. | Keep at it, all languages seem hard at first (though I would rather learn another programming language than do my french gcse, yikes!) Quote:
__________________ | |
| |
| | #10 (permalink) | |
| NamePros Regular | Quote:
Code: onclick="window.open='http://gmail.com'" Code: onclick="window.open('http://gmail.com');"
| |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |