/    Sign up×
Community /Pin to ProfileBookmark

Why doesn’t this work? JAVA/PHP/Joomla question

When I use the following code on a regular web page I have no issues but when I load it in PHP/Joomla, neither script works & I get some of the script output at the top of the screen. I know I’m a Javascript idiot but it has to be something simple I’m overlooking.

Here’s the link to my site where you can see the results: [URL=”http://www.lovesongsforsale.com/index.php/Valentines/”][/URL]

[CODE]<script type=”text/javascript”>
var lyrics =
“Such a fine little girl, my little <b>:::</b>.<br />”+

var Content = lyrics;
function updateContent(obj){
Content = lyrics;
var objContent = document.getElementById(‘ContentID’);
Content = Content.replace(/:::/g,obj);
objContent.innerHTML = Content;
}

var names = “{mp3}::1{/mp3}<br>” + “<a href=http://www.::1.com> Add to cart</a>”
;
var Content = names;
function updateNameList(obj){
Content = names;
var objContent = document.getElementById(‘namelinksID’);
Content = Content.replace(/::1/g,obj);
objContent.innerHTML = Content;
}
</script>

<table cellspacing=”0″ cellpadding=”0″ width=”100%” border=”0″>
<tbody>
<tr>
<td valign=”top” width=”70%”>
<p>{tab=Song Info} <span class=”SongType”>THIS PAGE IS UNDER CONSTRUCTION – PLEASE CHECK BACK IN AUG ’08!</span></p>
<p><span class=”SongHead”>Description:</span></p>
<p>Ahh young love. Whether you’ve been married for years, remembering the first time you met or you’re thinking about proposing to the girl of your dreams, this song will sum up your feelings perfectly.</p>
<div class=”Songinfo” id=”SongInfo”>
<p><span class=”SongHead”><img alt=”” align=”left” src=”/images/stories/iconmusicstaffwglobe.png” /></span><span class=”SongHead”>Song Type: </span><span class=”SongType”>Your Name Here</span> <strong><br />
&quot;Valentine&quot;</strong> is a &quot;Your Name Here&quot; song which means it <u><strong>is available for immediate download</strong></u>.</p>
<br />
<p><strong><img alt=”” align=”left” src=”/images/stories/help.png” /></strong><strong>How does it work? </strong>Play the original song (to the right –&gt;) &amp; then listen to the version with your loved one’s name in it (below). View the lyrics tab (^above) to see how their name will fit in the song.</p>
<br />
<p><strong>What if their name is not on the drop down list?</strong> Contact us (<a href=”index.php/Contact-Us/”>here</a>) &amp; request the name to be added. We will contact you when it’s ready for download.</p>
<br />
<p><strong><img alt=”” align=”left” src=”/images/stories/headphonescart.png” /></strong><strong>Awesome! I’m ready to download! What’s next? </strong>Select the name from the list below &amp; add it to your cart. You may also want to view our <a target=”_blank” href=”index.php/Gift-Packages/Gift-Packages.html”>gift packages</a> to make it a great gift!</p>
<p>&nbsp;</p>
<hr />
<p><strong><img height=”50″ alt=”” width=”50″ align=”left” src=”images/stories/iconmusicstaffwpencil.png” /></strong><strong><span class=”SongHead”>Song Type: </span><span class=”SongType”>Melody Template Song</span><br />
</strong><strong>Want it in your own words? </strong>This song is also available in Melody Template format. It is the same song, with the melody but no lyrics. Simply fit your own words/lyrics to the melody &amp; voila! A beautiful song from your heart!</p>
<br />
<p align=”left”><strong><img alt=”” align=”left” src=”/images/stories/help.png” /></strong><strong>OK, I’m interested in trying my own lyrics. What’s next? </strong></p>
<div align=”center”><span class=”SongPlayerTitle”>Listen to the &quot;My Little Valentine&quot; Melody Template. <br />
</span>{mp3}valentinemelody{/mp3}</div>
<p>Need help with lyrics ideas? Go <a target=”_blank” href=”http://www.lyricideas.com/”>here</a>. *Yes you can use our lyrics if that’ll help!</p>
<br />
<p><strong><img alt=”” align=”left” src=”/images/stories/headphonescart.png” /></strong><b>Ready to try it?</b> Go <a href=”index.php/component/option,com_rsform/Itemid,140/”>here</a> to complete our <strong>Melody Template Form</strong> &amp; we’ll get started on your new song!</p>
<p>&nbsp;</p>
<p>Please order at least 4 weeks in advance of Valentine’s Day! Rush orders are available.</p>
</div>
<p><img style=”width: 429px; height: 25px” height=”32″ alt=”musicstaff3divider.gif” width=”32″ align=”bottom” src=”/images/stories/musicstaff3divider.gif” /><br />
{tab=Lyrics} </p>
<p>
<select id=”nameID” onchange=”updateContent(this.value);” name=”names”>
<option value=””>Select Name</option>
<option value=”Angela”>Angela</option>
<option value=”Ashley”>Ashley</option>
<option value=”Brittney”>Brittney</option>
</select>
</p>
</p>
<div class=”contentBox” id=”contentID”>
Select a name from the select boxes above.
</div>
<p>&nbsp;</p>
<p style=”text-align: center”><span><img style=”width: 409px; height: 25px” height=”32″ alt=”musicstaff3divider.gif” width=”32″ align=”bottom” src=”/images/stories/musicstaff3divider.gif” /></span></p>
<p>{tab=Story Behind Song}<img id=”songwriter” height=”101″ alt=”” hspace=”5″ width=”100″ align=”left” vspace=”5″ name=”songwriter” src=”/images/stories/songwriteratpiano.jpg” /></p>
<p>Ryan originally wrote this song for this girlfriend at the time. They’d seen each other at parties but never got the chance to really talk. Ryan said, &quot;There was something in her eyes that told me she liked me but I wasn’t sure. And even though I hardly knew her, she was all I could think about. <br />
<br />
I started playing guitar &amp; this it just came out. It was written in 30 minutes. Those are always the best songs, the ones that write themselves.&quot;</p>
<br />
{xtypo_quote} even though I hardly knew her, she was all I could think about – Ryan{/xtypo_quote}
<p>&nbsp;</p>
<p>By the time they finally got together, he developed such strong feelings for her, he was already deeply in love &amp; had a wonderful song to show her.</p>
<br />
<p style=”text-align: center”><span><img style=”width: 409px; height: 25px” height=”32″ alt=”musicstaff3divider.gif” width=”32″ align=”bottom” src=”/images/stories/musicstaff3divider.gif” /></span></p>
</td>
<td>&nbsp;</td>
<td valign=”top” align=”center” width=”50%”>
<table height=”223″ cellspacing=”0″ cellpadding=”0″ width=”205″ align=”right” border=”0″ border-style=”inset”>
<caption>
<p>&nbsp;</p>
<br />
</caption>
<tbody>
<tr>
<td bgcolor=”#ededed” colspan=”2″>
<p class=”style1″ style=”text-align: center”><img height=”147″ alt=”couplesmiling200width.jpg” width=”200″ src=”/images/stories/couplesmiling200width.jpg” /></p> </td>
</tr>
<tr>
<td bgcolor=”#ededed”>
<p class=”style1″><img height=”50″ alt=”” hspace=”3″ width=”50″ align=”left” vspace=”3″ src=”/images/stories/headphonesplay.png” /></p> </td>
<td bgcolor=”#ededed”>{mp3}valentine{/mp3}</td>
</tr>
<tr>
<td style=”text-align: center” bgcolor=”#ededed” colspan=”2″>
<p class=”SongPlayerTitle”>Listen to &quot;My Little Valentine&quot;</p> </td>
</tr>
<tr>
<td style=”text-align: center” bgcolor=”#ededed” colspan=”2″><hr /> </td>
</tr>
<tr>
<td style=”text-align: center” bgcolor=”#FFCC33″><img src=”/images/stories/girluser.png” alt=”” width=”48″ height=”48″ hspace=”3″ align=”left” /></td>
<td style=”text-align: center” bgcolor=”#FFCC33″>Names available<br>
<select id=”peopleID” onChange=”updateNameList(this.value);” name=”people”>
<option value=””>Select Name</option>
<option value=”Angela”>Angela</option>
</select></td>
</tr>
<tr>
<td colspan=”2″ bgcolor=”#FFCC33″ style=”text-align: center”><div id=”namelinksID”> * </div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
[/CODE]

Thanks in advance for your help!

to post a comment
JavaScript

16 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyJul 21.2008 — Remove the + from the end of the second line? What's it there for?
Copy linkTweet thisAlerts:
@sarmstroauthorJul 21.2008 — That's actually my script, but abbreviated for the forum. It actually ends with a ; I just cut out the rest so it would fit. If you see the page @ http://www.lovesongsforsale.com/index.php/Valentines/, you'll see it seems to have a problem with

" + " Add to cart" ; var Content = names; function updateNameList(obj){ Content = names; var objContent = document.getElementById('namelinksID'); Content = Content.replace(/::1/g,obj); objContent.innerHTML = Content; } [/QUOTE]

It may be an issue with the + in that line.
Copy linkTweet thisAlerts:
@sarmstroauthorJul 23.2008 — Any ideas? I'll add more to my post if I'm leaving something out that'll help.
Copy linkTweet thisAlerts:
@toicontienJul 23.2008 — Can you give us the JavaScript error? You might want to load this page up in Firefox and then click "Tools" and select "Error Console" to get a useful error message.
Copy linkTweet thisAlerts:
@sarmstroauthorJul 23.2008 — Wow, I've never thought to use the Firefox error tool to see Javascript errors - I've just used it for checking css errors but thank you for the tip, it's a great tool. Here's the error I recieved.

Error: unterminated string literal

Source File: http://www.lovesongsforsale.com/index.php/Valentines/

Line: 317, Column: 14

Source Code:

var names = "[/QUOTE]


I guess it means I need to add a close quote somewhere?
Copy linkTweet thisAlerts:
@sarmstroauthorJul 23.2008 — I checked the code & it did have closed quotes on the line. I did get another error however - Error: writethis is not defined

Source File: http://www.lovesongsforsale.com/index.php/Valentines/

Line: 325

Any ideas?
Copy linkTweet thisAlerts:
@toicontienJul 23.2008 — In the source code for that page, I see:
var Content = lyrics;
function updateContent(obj){
Content = lyrics;
var objContent = document.getElementById('ContentID');
Content = Content.replace(/:::/g,obj);
objContent.innerHTML = Content;
}

[B]var names = '[/B]

&lt;!-- JW AllVideos Plugin (v2.4) starts here --&gt;

The boldface text is the "unterminated string literal" that Firefox is referring to.
Copy linkTweet thisAlerts:
@toicontienJul 23.2008 — Looking at the source code, it looks like the [B]names[/B] variable is getting raw HTML. Is there PHP code that is writing the value of the [B]names[/B] variable to the page?
Copy linkTweet thisAlerts:
@sarmstroauthorJul 28.2008 — Thank you for your response. I'm sorry I didn't see it sooner, my subscription is not working for some reason. Anyway, I created the names variable. I agree that's the problem. I just can't figure out what I'm doing wrong. Thanks in advance for your help.
Copy linkTweet thisAlerts:
@toicontienJul 28.2008 — Since you are using PHP and Joomla for a CMS, you need to pass the text that goes in the [B]name[/B] JavaScript variable through the PHP urlencode() function.
[code=php]var name = '<?php echo urlencode($name_text); ?>';[/code]
Then when you want to insert that HTML, you use the JavaScript decodeURIComponent() function:
var myDiv = document.getElementById("someDivID");

myDiv.innerHTML = [B]decodeURIComponent(name)[/B];
Copy linkTweet thisAlerts:
@sarmstroauthorJul 29.2008 — I'm sorry, I don't know enough to know how to adjust my script to reflect your excellent suggestions. Any chance you can go here http://www.lovesongsforsale.com/index.php/Valentines/ & show me how your code would be inserted?
Copy linkTweet thisAlerts:
@toicontienJul 29.2008 — We'll first need to adjust the PHP script. How is the [B]names[/B] variable being echo'd to the page? Can you show me that PHP code?
Copy linkTweet thisAlerts:
@ChazzlJul 29.2008 — toicontien is correct, your javascript "names" variable is corrupt. It appears that this variable is assigned the content of the "JW AllVideos Plugin" instead of what I expect is intended.

A diagnosis of exactly how this error is being created cannot be made from the end user view. The issue is in the server side logic.

See attachment for what the output should look like to solve the problem. The topic at hand is around line 305.

[upl-file uuid=c12ec94b-d648-48e0-bf99-4c2e9815544e size=29kB]Valentines HTML.txt[/upl-file]
Copy linkTweet thisAlerts:
@sarmstroauthorAug 11.2008 — What if I change the variable from names to peeps? Could it be that simple?
Copy linkTweet thisAlerts:
@toicontienAug 11.2008 — Not even close ? The value you assign the [B]names[/B] variable needs to be encoded. That's how you solve your problem. So again I ask, can we see the PHP that writes the value of the [B]names[/B] variable to the page?
Copy linkTweet thisAlerts:
@sarmstroauthorAug 11.2008 — I apologize for not responding quickly, I wasn't getting notices when the forum was updated. I tried to paste in the PHP code but it was over 3K lines & the forum forced me to truncate it so I just pasted in what I could.

Using yours & JMRKER's help I was able to tweak it & get it working. I changed the names ID & that seemed to make a difference. Here's the link

http://www.lovesongsforsale.com/index.php/Valentines/

One last question :rolleyes:, I need to launch a new small window from a link that'll play an mp3 file in a small window. Here's my code,

[CODE]<script type="text/javascript">
var namelinks = '';
namelinks += '<img src="images/stories/headphonesplay.png" align="left">'; namelinks += '<a href="/images/stories/audio/::1.mp3" target=blank>Listen to <br> ::1 demo</a> <br> <br>'; namelinks += '<HR ...> <br>'; namelinks += '<img src="images/stories/headphonescart.png" width="" height="" align="left" alt="Download Song">'; namelinks += ' <a href="http://www.lovesongsforsale.com/index.php/My-Little-::1.html">Download <br> ::1s song</a>';

var Content1 = '';

function updateContent1(obj){
Content1 = namelinks;
var objContent = document.getElementById('LinkBox');
Content1 = Content1.replace(/::1/g,obj);
objContent.innerHTML = Content1;
}[/CODE]


How can I fit a new javascript inside the existing script? I'm trying to integate a window size control with my existing script. Here's the script I tried to integrate with no results:

[CODE]<A HREF="javascript:launchwin('yourpage.html' , 'newwindow' , 'height=150,width=300')">Your Link Goes Here</A> [/CODE]

Thanks in advance for your help & your patience!
×

Success!

Help @sarmstro spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...