I am trying
function ddtip(thetest, thetext)
var Test = document.all[thetest].innerHTML;
var str = document.all[thetext].value;
var MyArray = str.split(",");
but it is not working in Firefox but the same is working in IE. thetest and thetext are the ID of the Server Controls.
I also tried with document.getElementById[thetest].innerHTML; but it is throwing error.
Please Help.
Thanks,
Rahul
If "thetest" is a variable then getElementById should work. If it is the id of the element you are looking for then it should be like this: document.getElementById('thetest')
Related
I'm trying to make a text into a link in my Javascript code. This should work but it doesn't.
var strLink = "mysite.com" ;
var cb_header = chatbox.find('.imjs-header');
cb_header.html(cb_header.html().replace('{username}', strLink));
I have a variable called username and it is a string. That is the string that used to replace {username}. Maybe I can use jquery? I can't seem to get it a link though. Any pointers in the right direction are greatly appreciated.
Thank you,
Arjun
var strLink = '"mysite.com" ';
Try this:
var strLink = '"mysite.com" ';
I have this JavaScript function:
function Test(isValid) {
var divStart = $get('divDateFrom');
var divEnd = $get('divDateTo');
var txtStartDate = divStart.firstChild;
var txtEndDate = divEnd.firstChild;
var isValidFromForecastStartDate;
txtEndDate.setAttribute('dateInRegionalFormat', txtEndDate.value);
}
This function is working fine in IE but I'm getting "txtEndDate.setattribute is not a function" error in Firefox and Chrome.
Use jquery.attr() like,
$(txtEndDate).attr('dateInRegionalFormat', txtEndDate.value);
Updated there may be multiple elements so use [0] for the first element like,
txtEndDate[0].setAttribute('dateInRegionalFormat', txtEndDate.value);
You should first check whether the elements exists or not before setting attribute in it like,
if(txtEndDate.length)
{
txtEndDate.setAttribute('dateInRegionalFormat', txtEndDate.value);
}
You can do it by this way:
txtEndDate['dateInRegionalFormat'] = txtEndDate.value;
instead of old code:
txtEndDate.setAttribute('dateInRegionalFormat', txtEndDate.value);
I have faced the same kind of issue very recently. Try to get rid of ".value" part. It may work for you.
txtEndDate.setAttribute('dateInRegionalFormat', txtEndDate);
I work on XMLResponse and try to find count value from xmlresponse.For that i write this code
this is my response in alert box
cnt = Math.ceil($(xmlResponse1).find("count").text()/250);
alert(cnt);
it works in IE9 but return null ni IE8 and IE7.
Please help me.
What Should have to do for solve this problem.
Thanks and Regards
The $() function is not suited for parsing XML. Use $.parseXML before wrapping the elements inside a jQuery object.
var cnt = Math.ceil($($.parseXML(xmlResponse1)).find("count").text()/250);
alert(cnt);
You can see it working in IE8 in this Fiddle
Or in easier to read way, caching the parsed XML document:
var xmlDOM = $.parseXML(xmlResponse1);
var cnt = Math.ceil( $(xmlDOM).find("count").text()/250 );
Updated demo
I think that text() does not work in ie7-8, try html():
cnt = Math.ceil($(xmlResponse1).find("count").html()/250);
Take a look at this question: jquery ie8 get text value = Object doesn't support this property or method
I am dumping some CSS into a div and I am looking to format it so it is more legible. Basically what I want to do is insert a break tag after every semicolon. I have searched around for a while but can't seem to find something that quite fits what I am trying to do.
I have something like this...
HTML
<div class='test'>
color:red;background-color:black;
</div>
jQuery
var test = $('.test').text();
var result = test.match(/;/g);
alert(result);
And I have tried..
var test = $('.test').text();
var result = test.match(/;/g);
result.each(function(){
$('<br/>').insertAfter(';');
});
alert(result);
Also I have started a fiddle here.. Which basically just returns the matched character...
http://jsfiddle.net/krishollenbeck/zW3mj/9/
That is the only part I have been able to get to work so far.
I feel like I am sort of heading down the right path with this but I know it isn't right because it errors out. I am thinking there is a way to insert a break tag after each matched element, but I am not really sure how to get there. Any help is much appreciated. Thanks...
try it like this
var test = $('.test').text();
var result = test.replace(/\;/g,';<br/>');
$('.test').html(result);
http://jsfiddle.net/Sg5BB/
You can use a normal javascript .replace() method this way:
$(document).ready(function(){
$(".test").html($(".test").html().replace(/;/g, ";<br />"));
});
Fiddle: http://jsfiddle.net/SPBTp/4/
Use This CODE
var test = $('.test').text();
var result = test.split(';').join(';<br />')
http://jsfiddle.net/FmBpF/
You can't use jQuery selectors on text, it only works on elements.
Get the text, just replace each ; with ;<br/>, and put it back.
$('.test').html($('.test').text().replace(/;/g, ';<br/>'));
Try something like this :
var test = $('.test').text();
var result = test.replace(/;/g,";");
$('.test').html(result);
That should work if you stick it into your jfiddle.
I try to implement the following code:
html
<span id = "myset">school</span>
Javascript
var myset =$("#myset").val();
var ID=$("#data li:last").attr("id");
$.get('page.php', 'id='+ID+'&set='+myset, function(newdata){
$('#data').append(newdata);
});
In the page.php file, it doesn't receive the value of the $_GET['set'], but if I change
var myset =$("#myset").val();
to:
var myset ='school';
everything works fine in this case, what am I doing wrong, anyone could help me, thanks.
I also tried
var myset =document.getElementById("myset").value;
but it is still not working;
Span tags don't have a value, they have .innerText or .innerHTML or, with jQuery, .html() or .text()
"school" isn't the value of your span. It is the data of a text node inside your span. You can access it like this:
var myset = $("#myset").text();
Use var myset =$("#myset").text(); instead.