By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,829 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

how to getAttribute of value

P: 77
Hello all,, i have a question, please help me to find out

i have this script (in js function)
Expand|Select|Wrap|Line Numbers
  1. var td = document.createElement('td');
  2. var p = document.createElement('p');
  3. var label = document.createElement('label');
  4. var span = document.createElement('span');
  5. var theTextarea = document.createElement('textarea');
  6. theTextarea.setAttribute('name', 'work_description');
  7. theTextarea.setAttribute('value','');
  8. span.appendChild(theData);
  9. label.appendChild(span);
  10. label.appendChild(theTextarea);
  11. p.appendChild(label);
  12. td.appendChild(p);
  13. row.appendChild(td);
  14. theTextarea.onchange = function(){theTextarea.getAttribute('value'));}
  15.  
With command "theTextarea.onchange...", i want to get a value from html object form (textarea) that has been input by user.
But with that command, i always get null (empty string) value.

Any idea??thanks
Jul 14 '08 #1
Share this Question
Share on Google+
11 Replies


acoder
Expert Mod 15k+
P: 16,027
theTextarea should be replaced by 'this':
Expand|Select|Wrap|Line Numbers
  1. theTextarea.onchange = function(){this.getAttribute('value'));}
PS. please use code tags when posting code. See How to Ask a Question.
Jul 14 '08 #2

P: 77
ok thanks, it works perfectly..
Jul 14 '08 #3

hsriat
Expert 100+
P: 1,654
And remove the extra bracket after ('value')
Jul 14 '08 #4

acoder
Expert Mod 15k+
P: 16,027
And remove the extra bracket after ('value')
Oh, I didn't see that. Thanks for pointing out :)
Jul 14 '08 #5

acoder
Expert Mod 15k+
P: 16,027
ok thanks, it works perfectly..
Glad to hear it. If you have any more questions, just post back to the forum.

PS. welcome to the site. I notice that you've just joined. Happy posting!
Jul 14 '08 #6

hsriat
Expert 100+
P: 1,654
Oh, I didn't see that. Thanks for pointing out :)
You are welcome. :)
(Perhaps this is the first time)
Jul 14 '08 #7

acoder
Expert Mod 15k+
P: 16,027
Lol, there's always a first time for everything ;)
Jul 14 '08 #8

P: 77
actually, with that command, i want to make a validation. So if the object textarea is empty or user doesn't input text to the object textarea, than i will generate an alert ("required field...")..

and of course, first i'd like to get a value that user input from the textarea object with this script

theTextarea.onchange = function(){
alert(this.getAttribute('value'));
}


It is works perfectly with that command, and no error founded, but the alert is shown if user input any character to the textarea object.
If user didn't input a value (it means user press "tab" to jump from the textarea object to another object), the alert of value won't come out.

So the alert is shown if only the user input a value to the textarea object.

any idea?
Jul 15 '08 #9

hsriat
Expert 100+
P: 1,654
I guess you are in need of onblur event.
Jul 15 '08 #10

P: 77
i have changed into onblur event, but still, it won't work..more advice?
Jul 15 '08 #11

acoder
Expert Mod 15k+
P: 16,027
You have to check the input. Check if it's empty or whatever other checks you want to make. Note though that onblur can sometimes fire unexpectedly, so I wouldn't use alerts (which can be annoying). I'd use DHTML to show a message next to the field.
Jul 15 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.