i want to change the attribute of a text element from required to not required. I am using javascript to do this. i am calling a function based on the input of the radio button and i am using html 5..
-
1post example to jsFiddle please!Ilia Ross– Ilia Ross2012-08-21 10:12:49 +00:00Commented Aug 21, 2012 at 10:12
-
@MihaiIorga i was validation the form elements before clicking submit button. bcoz there was a property in the html5 called required.SHiv– SHiv2012-08-21 10:26:32 +00:00Commented Aug 21, 2012 at 10:26
Add a comment
|
1 Answer
document.getElementById("adiv").removeAttribute("style")
document.getElementById("myimage").setAttribute("src","another.gif")
var getvalue=document.getElementById("myimage").getAttribute("src")
Now but it in a function and use it how you wish.
That is how you get set and remove attributes in JavaScript.
Source: http://www.javascriptkit.com/dhtmltutors/domattribute.shtml
3 Comments
SHiv
i tried this code document.getElementsByName("twelthPercentage").setAttribute("required"); but i didn't work can u tell me why
Lemex
document.getElementsByName("twelthPercentage").setAttribute("required","true") maybe? please create a JS fiddle with issues or read teh documentation
Jukka K. Korpela
@Sivashankar, you probably need to use getElementById not getElementsByName. If problems continue, please post sufficient part of the code.