Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
27
rated 0 times [  34] [ 7]  / answers: 1 / hits: 77500  / 11 Years ago, tue, october 29, 2013, 12:00:00

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.


More From » asp.net

 Answers
0

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);
}

[#74656] Monday, October 28, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
analiseb

Total Points: 252
Total Questions: 96
Total Answers: 106

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
;