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

getAttribute of value from drop down list

P: 77
I have this script...
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 theData = document.createTextNode('Chart Of Account');
  6.     var theSelect = document.createElement('select');
  7.     theSelect.setAttribute('name', 'items['+item_count+'][pbdccoa]');
  8.     var opCol = document.createElement('option');
  9.     opCol.setAttribute('value', '');
  10.     var opColTxt = document.createTextNode('<?php echo $this->lang->line('select_coa')?>');
  11.     opCol.appendChild(opColTxt);
  12.     theSelect.appendChild(opCol);
  13.     <?php foreach($coa_list->result() as $coa): ?>                            var opCol = document.createElement('option');
  14.     opCol.setAttribute('value', '<?php echo $coa->ccbcCoa?>');
  15.     var opColTxt = document.createTextNode('<?php echo $coa->ccbcCoa?>');
  16.     opCol.appendChild(opColTxt);
  17.     theSelect.appendChild(opCol);            
  18.     <?php endforeach; ?>
  19.     opCol.onselect = function(){
  20.     if (this.getAttribute('value')==null || this.getAttribute('value')==""){
  21.         alert("Require field");
  22.         }
  23.     }
  24.     span.appendChild(theData);
  25.     label.appendChild(span);
  26.     label.appendChild(theSelect);
  27.     p.appendChild(label);
  28.     td.appendChild(p);
  29.     row.appendChild(td);
  30.  
With this command below i want to check the value of drop down list, if user select a null value of drop down list, than it will show an alert window ("Require Field").

Expand|Select|Wrap|Line Numbers
  1. if (this.getAttribute('value')==null || this.getAttribute('value')==""){
  2.         alert("Require field");
  3.         }
  4. }
  5.  

But it doesn;t work well, any idea??thanks for helping me..
Jul 15 '08 #1
Share this Question
Share on Google+
3 Replies


rnd me
Expert 100+
P: 427
xbrowser onchange:

Expand|Select|Wrap|Line Numbers
  1. <select onchange"var ti=this.selectedIndex;var op=this.options; if(op[ti].value){ alert(op[ti].value); }">
Jul 15 '08 #2

P: 77
xbrowser onchange:

Expand|Select|Wrap|Line Numbers
  1. <select onchange"var ti=this.selectedIndex;var op=this.options; if(op[ti].value){ alert(op[ti].value); }">

sorry i dont understand with that, where do i must put that script??
thanks
Jul 17 '08 #3

acoder
Expert Mod 15k+
P: 16,027
onselect is only for text inputs and textareas. Use onchange on the select element, e.g.
Expand|Select|Wrap|Line Numbers
  1. theSelect.onchange = function() {
  2.     if (this.value == "") alert("Required Field");
  3. }
Jul 17 '08 #4

Post your reply

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