Reputation: 395
i have this interface :
When the "Add Another One" button is clicked, i will have to add another interface that looks the same as this one, so that the whole interface would look something like this :
I had the attribute onfocus for the textarea in order to clear it content when in focus, and it is working prefectly, this is the code for it :
<textarea name="educationDescription1" id="educationDescription1" rows="5" cols="33" onfocus="clearContents(this);">Describe your studying experience in a couple of sentences.</textarea>
Now I'm having problems doing the same for the created textarea, although i have used the same syntax! This is the code used for creating the new text area :
var node6 = document.createElement("textarea");
node6.rows="5";
node6.cols="33";
node6.onfocus="clearContents(this);";
node6.value="Describe your working experience in a couple of sentences.";
node6.name="experienceDescription"+experiences;
node6.id="experienceDescription"+experiences;
Any idea what could be the problem? Thanks
Upvotes: 0
Views: 197
Reputation: 4718
I guess you might want to use placeholder
attribute instead of onfocus
.
If you use onfocus
, the textarea would be cleared everytime the user make a focus on it even after the user input valid data.
The code to set placeholder
with jQuery could be something like this:
var node6 = $("<textarea></textarea>");
...
node6.attr('placeholder','Describe your working ...');
Here is the fiddle. http://jsfiddle.net/naokiota/j687tg80/2/
Hope this helps.
Upvotes: 1
Reputation: 4896
In node6.onfocus
, onfocus
needs a function reference. You are assigning a string. It should be something like,
node6.onfocus=function(){clearContents(this);};
Or you can use addeventListner
function
node6.addEventListener('onfocus',function(){clearContents(this);});
Or if you want to add onfocus into the html you have to create a new attribute and set it like this.
var attr = document.createAttribute('onfocus');
attr.value="clearContents(this)";
node6.setAttributeNode(attr);
Upvotes: 1
Reputation: 1661
This:
node6.onfocus="clearContents(this);";
Should be replaced by this:
node6.onfocus=function(){clearContents(this);};
Upvotes: 1