Solved

JavaScript syntax question (Urgent please)

Posted on 2015-02-17
1
102 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SP result not being displayed 5 44
What is the correct way to check for empty value in input field 2 20
Slush on text 2 11
title attribute 5 26
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime is disastrous for companies and can lead to major hits on a brand, reputation, an…
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

726 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