1

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..

2
  • 1
    post example to jsFiddle please! Commented 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. Commented Aug 21, 2012 at 10:26

1 Answer 1

4
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

Sign up to request clarification or add additional context in comments.

3 Comments

i tried this code document.getElementsByName("twelthPercentage").setAttribute("required"); but i didn't work can u tell me why
document.getElementsByName("twelthPercentage").setAttribute("required","true") maybe? please create a JS fiddle with issues or read teh documentation
@Sivashankar, you probably need to use getElementById not getElementsByName. If problems continue, please post sufficient part of the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.