I'm creating the following div using javascript, task_id is an int and person_name is a string, why is my alert not working!
when i send 2 integers, the alert works fine, when i send 2 strings the alert still doesn't work, what am i doing wrong?
'<div " onMouseOver="Drag(' + task_id + ',' + person_name +');"</div>'
.....
function Drag(id, name){
alert(id + " " + name);
}
thanks a million in advance
You need to correctly add escaped string delimiters around the string, otherwise you're sending a variable with the name of person_name's value. Try:
'<div onMouseOver="Drag(' + task_id + ',\'' + person_name +'\');"></div>'
Related
I'm using the EMail function in PL/SQL.
The function getting called by Javascript after button got clicked.
This working very fine.
My Problem is that I generate the EMail Body in Javascript using PL/SQL variables.
Code Looks like
var content = "Hello " + '|| chr(13)||chr(10)||' + " " + " Name: " + "'||v_name ||'" + '||chr(13)||chr(10) ||' + " ";
So here the problem chr(13)||chr(10) returning the character 0 in the string.
But i want a Newline.
I tried with \r\n which didn't worked.
HTML-Tags also don't work because my Email Provider giving me th HTML-Tags out.
Excuse my english :)
Hope someone can help me.
I tried with the '\r\n' in javascript and it worked for me.
var content = "Hello " + '\r\n' + " " + " Name: " + "'||v_name ||'" + '\r\n' + " Test";
alert(content);
below is the sample jsfiddle for the same.
https://jsfiddle.net/njbjusmk/.
I'm not sure yet, but you might've messed something up with your apostrophes.
Maybe you should try parsing your content as follows:
var content = "'Hello '||CHR(13)||CHR(10)||' Name: ||" + v_name + "'||CHR(13)||CHR(10)||' " + " Message body "+ "'";
I'm building a string of text using HTML and variables from a JSON file. The issue is that the quotation marks from the HTML are conflicting with the quotations from the js expression - specifically when I'm trying to build a URL from a string of a URL partial + a json variable.
Here's my code. Any help?
output += '<li><span><a>' +
jobs[i].title +
'</a></span><span>' +
jobs[i].city +
'</span><span><a href='http://user.theresumator.com/apply/'' +
jobs[i].board_code +
'><button>More Info ›</button></a></span></li>';
}
My desired outcome is something like:
<li><span><a>Social Impact Strategist (Los Angeles or New York)</a></span><span></span><span><button>More Info ›</button></span></li>
Escape your quotes with \:
output += '<li><span><a>' +
jobs[i].title +
'</a></span><span>' +
jobs[i].city +
'</span><span><a href=\'http://user.theresumator.com/apply/' +
jobs[i].board_code +
'\'><button>More Info ›</button></a></span></li>';
}
or use double quotes ":
output += '<li><span><a>' +
jobs[i].title +
'</a></span><span>' +
jobs[i].city +
'</span><span><a href="http://user.theresumator.com/apply/' +
jobs[i].board_code +
'"><button>More Info ›</button></a></span></li>';
}
The 2nd one will match your desired outcome with double quotes perfectly.
Here's the working code! I broke it out on a separate line and add double quotes by themselves contained in single quote.
output += '<li><span><a>' +
jobs[i].title +
'</a></span><span>' +
jobs[i].city +
'</span><span><a href=' +
'"http://user.theresumator.com/apply/' +
jobs[i].board_code +
'"' +
'><button>More Info ›</button></a></span></li>';
}
In javascript I am creating a li element as per below which contains only the problem I am seeing.
The data-videoUrl is showing the full url, so all good there.
The issue is the entry.link and entry.title, while debugging, I verified the strings are within quotes. i.e. "This is a pod cast." The data-videoTitle and data-videoDesciption are being truncated though. i.e. "This" will show from the previous example.
I'm not sure what is occuring in the latter two data assignments as I've verified the text is not double quoted etc. What is occuring with the html5 data elements? I can provide a more complete example if needed.
var podItem = document.createElement("li");
podItem.innerHTML = entry.title
+ "<a data-videoUrl=" + entry.link + " "
+ "data-videoTitle=" + entry.title + " "
+ "data-videoDescription=" + entry.contentSnippet + " "
+ "</a>";
document.getElementById("podCastList").innerHTML += podItem.innerHTML;
Here is a the html being generated.
<a data-videourl="http://rss.cnn.com/~r/services/podcasting/studentnews/rss/~3/d3y4Nh_yiZQ/orig-sn-060614.cnn.m4v" data-videotitle="CNN" student="" news="" -="" june="" 6,="" 2014="" data-videodescription="For" our="" last="" show="" of="" the="" 2013-2014="" school="" year,="" cnn="" takes="" a="" look="" back,="" ahead,="" and="" at="" stories="" making="" ...="" <=""></a>
I'm sure there's something I'm not fully understanding. Why would the first data element get the text correctly, and the next two data elements break up the text as in: [data-videotitle="CNN" student="" news=""]. The text is a straight forward sentence quoted i.e. "CNN student news..."
Why would videoUrl work correctly and the other two not?
You need to add some quotes around the attributes...
podItem.innerHTML = entry.title
+ "<a data-videoUrl=\"" + entry.link + "\" "
+ "data-videoTitle=\"" + entry.title + "\" "
+ "data-videoDescription=\"" + entry.contentSnippet + "\" "
+ "</a>";
You'll also want to make sure you escape any quotes that are inside the attributes as well.
The code dynamically creates a listview which works but i want to make it so when a listview item is clicked it sends the a url paramater to another method. When i set a paramater it doesnt alert the paramater, but when i give no parameter it works.
var output =
"<li onclick='openURL()'><h3> Module Code: " +
results.rows.item(i).module
+ "</h3>Room: "
+ results.rows.item(i).room +
"</li>";
The above works - No parameter in openURL();
var output =
"<li onclick='openURL('" + results.rows.item(i).url + "')'><h3> Module Code: " +
results.rows.item(i).module
+ "</h3>Room: "
+ results.rows.item(i).room +
"</li>";
The above doesnt work - I have done alert(results.rows.item(i).url) and it has a value.
function openURL(url) {
alert("opening url " + url);
}
Could someone explain what i'm doing wrong, i've been trying to solve the problem for hours.
Cheers!
You are using single quotes to open the HTML attribute, you can't use it as JavaScript String because you'll be closing the HTML attribute, use double quotes:
var output =
"<li onclick='openURL(\"" + results.rows.item(i).url + "\")'><h3> Module Code: " +
results.rows.item(i).module
+ "</h3>Room: "
+ results.rows.item(i).room +
"</li>";
I am trying to iterate through all form elements with id that begins with a specified prefix and create an xml string with results, but it is getting a bit complicated as forms form input types seem to have different behaviors . Does this functionality already javascript, jQuery or third party jQuery module?
function fnPreIterate(){
var XMLstring;
$(':input[id*="f1"]').each(function() {
XMLstring += (" <" +this.name+ '>' + this.value + "</" + this.name + "> " );
});
$('#XMLstring').html("<pre>" + fnEncodeEntities(string) + "</pre>");
};
If you use:
$(this).val()
instead of
this.value
you'll save a lot of headaches with difference in form elements.
Another way to iterate is to use .serializeArray():
$.each($('#form').serializeArray(), function() {
string += (" <" +this.name+ '>' + this.value + "</" + this.name + "> " );
});
Hope this helps. Cheers
PS: To select by prefix, you should do $(':input[id^="f1"]') (use ^ instead of *)
Use $(this).val() to get the value.
Additionally you mixed up XMLString and string which results in your code creating a global variable and failing when it's called a second time.
Using jQuery you should try:
function fnPreIterate(){
var XMLstring='';
$(':input[id^="f1"]').each(function() {
var e = $(this), name=e.attr('name'), val=e.val();
XMLstring += (" <" +name+ '>' + val + "</" + name + "> " );
});
$('#XMLstring').html("<pre>" + fnEncodeEntities(XMLstring) + "</pre>");
};
I think it should work
You could make use of jQuery's serializeArray.
What is the problem you are facing?
try using $(this) selector in your function instead. something like this
$(this).attr('name') and $(this).val()