need help to fix the link in my javascript code - javascript

can some one help me to fix this link in my javascript code
the code is
$('.frame_src').attr('src', 'https://www.youtube.com/embed/' + $(this).data('str'));
full link is https://www.youtube.com/embed/p9zdCra9gCE?&vq=hd720&rel=0;autoplay=1
i want to make it something like this i know it's wrong but i can't fix it
$('.frame_src').attr('src', 'https://www.youtube.com/embed/' '?&vq=hd720&rel=0;autoplay=1' + $(this).data('str'));

You're almost there, you need to insert the $(this).data('str') value in the right place.
Change
$('.frame_src').attr('src', 'https://www.youtube.com/embed/' '?&vq=hd720&rel=0;autoplay=1' + $(this).data('str'));
to
$('.frame_src').attr('src', 'https://www.youtube.com/embed/' + $(this).data('str') + '?&vq=hd720&rel=0;autoplay=1');

Related

Simple Javascript Image

`jQuery('#resultWorkingDays').html(numberWithCommas(resultWorkingDays) + ' days')`
Using above prints 'days' on the end of a string. I want to change 'days' to an image source. I've searched & tried a lot of different things but none seem to work.
Complete JS novice, help much appreciated
Just include the HTML.
jQuery('#resultWorkingDays').html(numberWithCommas(resultWorkingDays) + ' <img src="yourImage.jpg">');
jQuery("#resultWorkingDays").html(numberWithCommas(resultWorkingDays) + "<img src='\images\...\name.png />");

upgrading javascript that adds a link to a field

I am trying to change the Sales Stage field label to a hyperlink to pop up a new browser window.
Currently I have a form with a Sales Stage field that has a drop down::
The underlying HTML:
<td title="Select the sales process stage for the opportunity to indicate the probability of closing the opportunity." class="ms-crm-ReadField-Normal ms-crm-FieldLabel-LeftAlign" id="salesstagecode_c"><span class="ms-crm-InlineEditLabel"><span class="ms-crm-InlineEditLabelText" style="text-align: left; max-width: 115px;">Sales Stage</span><div class="ms-crm-Inline-GradientMask" style="display: none;">
</div></span></td>
or perhaps better formatted:
The function that I used previously worked on an older version of the form:
function csjs_AddHyperlinkToLabel(sFieldId, sURL, sWindowOptions) {
    var sCurrentLabel = $("label[for='" + sFieldId + "']").html();
    $("label[for='" + sFieldId + "']").html("" + sCurrentLabel + "");
}
the function above worked on a form with the following html::
What changes would be required to the javascript to change the Sales Stage field label to a hyperlink to pop up a new browser window?
Though I'd be very grateful for a solution, I'm looking for guidance on how to accomplish this. Thank you for your attention and time.
Unfortunately, the solutions below did not work. I ran this through the debugger and here's what I got http://screencast.com/t/fT6tHvXZzvc
The issue here is that we are passing “salesstagecode” to this function:
csjs_AddHyperlinkToLabel("salesstagecode", sPageURL, sWindowFeatures);
and this turns out to be NULL:
var sCurrentLabel = $("label[for='" + sFieldId + "']").html();
*
The issue is that Microsoft changed the way the forms are rendered and
the HTML of the rendered page will no longer work with the way the
function was written. The label is now in a span tag instead of a
label tag. I don't know if there is a way to identify that span and
change the contents to have new HTML to make the text link.
*
How do you update a span tag?
You need to add target="_blank" attribute in your hyperlink markup.
Simple:
change
.... onclick=\"window.open('" + sURL + "', null, '" ....
to
.... onclick=\"window.open('" + sURL + "', '_blank', '" ....

document.write (trouble with syntax adding a href)

I have been having trouble getting the correct string formatted for my document.write()function. Any help is greatly appreciated. Jsfiddle link below of what i have so far. Below is what I am trying to achieve.
jfiddle
<img style="height:100px;" src="https://web.fulcrumapp.com/api/v2/photos/+ myarray[i]+.jpg?token=3c04f586f4991a" />
Your Fiddle code is currently putting the link text inside the link tag itself. You should close the > before putting the link text ;)
Additionally, don't use document.write...
Thank you, Niet for the advice I am looking into how to do this another way, but for now I was able to figure out my syntax.
document.write("<li><img src=\"" + url + "" + myarray[i] + "\"></li>");

JavaScript variable as HTML link text

I am trying to something like this:
JS variable
I have seen multiple threads where someone is trying to do something similar but none of these solutions seem to be working for me. I am trying to pull data from an API and I would like to use a variable from the API as the text for the link. Right now I am using jquery to do this:
$('#tracktitle').append($("<a href='" + track.permalink_url + "' target='_blank'>Title</a><br>").html(track.title));
but would like to have the 'html(track.title)' in place of 'Title'
any help would be greatly appreciated
What about?
$('#tracktitle').append("<a href='" + track.permalink_url + "' target='_blank'>" + track.title +"</a><br>")
When you create a new element with jQuery you can pass just the tag as the first argument to $() and then pass an object with the various properties you want to set as the second argument:
$("<a></a>", {
href : track.permalink_url,
html : track.title
}).appendTo("#tracktitle")
.after("<br>");
Demo: http://jsfiddle.net/7CVnZ/

Why are some of my link titles are being placed outside of my <a> tags?

Here is a jsbin so you can see what I mean.
As you can see some of my link titles are being placed outside the tags. Initially I thought this was to do with the fact some of the titles were surrounded by double quotes. I build a function to replace these but it had no effect.
After logging the title[i] before it is appended into the DOM, I can't see any reason why some would be placed inside the tags and some outside. If any one has any suggestions I would be very interested to hear them.
in postURLs function, change the line:
$("#" + subreddit + " > ul").append("<li>" + title[i] + "</li>");
to:
$("#" + subreddit + " > ul").append("<li><a href='" + url[i] + "'>" + title[i] + "</a></li>");
(just added single quotes to href attribute)
that will solve your problem.
next time, please include the code in the question body as well.
cheers.

Categories