Solved

JavaScript syntax question (Urgent please)

Posted on 2015-02-17
1
106 Views
Last Modified: 2015-03-13
I am using the following JavaScript code in a .html file for my Jetty web application:

<script id="user-template" type="text/x-handlebars-template">
    <img src="assets/images/admin/redminus.png" class="user-delete-img">
    <div class="user_name admin-users-span-1">{{username}}</div>
    <div class="user_email admin-users-span-2">{{username}}</div>
</script>

The above script works. It obtains the "username" variable as expected. I am creating another .html file where I am using the same "username" variable but I am experiencing problem with syntax and it is not working. The following are the .html file code. I have written three versions of it. Could you please let me know which one has the correct syntax? The first one did not work. If none has the correct syntax, could you please help me correct it?

1.
<script id="footer-template" type="text/x-handlebars-template">
        <img src="http://mypage.com/t.png?t=map&p={{username}}"/>
</script>

2.
<script id="footer-template" type="text/x-handlebars-template">
        <img src="http://mypage.com/t.png?t=map&p="/>{{username}}
</script>

3.
<script id="footer-template" type="text/x-handlebars-template">
        <img src="http://mypage.com/t.png?t=map&p="{{username}}/>
</script>
0
Comment
Question by:toooki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 17

Accepted Solution

by:
Lucas Bishop earned 500 total points
ID: 40615939
What did not work with the first one? How did it render in your page source? Does t.png exist in the root directory?

I see version 1 as being correct. Here is an example of how each would render if username was johndough:

Version 1 would include johndough as a parameter on the image path with proper html syntax:
        <img src="http://mypage.com/t.png?t=map&p=johndough" />

Open in new window


Version 2 would render the image with an empty parameter for "p=" and the username "johndough" rendered in plain text next to the image.
<img src="http://mypage.com/t.png?t=map&p=" />johndough

Open in new window


Version 3 the image path would end with an empty "p=" and the username would likely cause the image to appear broken since it is not defined as being part of valid html code.
<img src="http://mypage.com/t.png?t=map&p="johndough />

Open in new window


If you create an image tag manually on the page, using a real username in the parameter string, does it render properly? For example:

        <img src="http://mypage.com/t.png?t=map&p=replacewithrealusername" />

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question