Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript for changing the value of a non required field

Tags:

javascript

Basically, I have the labels of the fields inside the input boxes and use onblur and onclick to clear the values etc. I also have some javascript to make sure the required files aren't submitted as the label e.g. first name contains the label First Name* and I don't want it submitted as First Name*.

Where I'm struggling is with the comments box. It isn't a required field so I don't want an alert to pop up, I just want the javascript to change the value to either blank or n/a if it's left as 'comments'. Here is the javascript code I am using to try and achieve this:

var comments=document.getElementById('comments').value;
if (comments=="comments")
{
    document.getElementById('comments').value="n/a";
}
like image 655
Jake Neal Avatar asked Nov 12 '22 20:11

Jake Neal


1 Answers

i think your comment field is a textarea.... use

document.getElementById('comments').innerText

instead

document.getElementById('comments').value
like image 104
silly Avatar answered Jan 04 '23 02:01

silly