getAttribute of value from drop down list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maminx
    New Member
    • Jul 2008
    • 77

    getAttribute of value from drop down list

    I have this script...
    [CODE=javascript]
    var td = document.create Element('td');
    var p = document.create Element('p');
    var label = document.create Element('label' );
    var span = document.create Element('span') ;
    var theData = document.create TextNode('Chart Of Account');
    var theSelect = document.create Element('select ');
    theSelect.setAt tribute('name', 'items['+item_count+'][pbdccoa]');
    var opCol = document.create Element('option ');
    opCol.setAttrib ute('value', '');
    var opColTxt = document.create TextNode('<?php echo $this->lang->line('select_c oa')?>');
    opCol.appendChi ld(opColTxt);
    theSelect.appen dChild(opCol);
    <?php foreach($coa_li st->result() as $coa): ?> var opCol = document.create Element('option ');
    opCol.setAttrib ute('value', '<?php echo $coa->ccbcCoa?>');
    var opColTxt = document.create TextNode('<?php echo $coa->ccbcCoa?>');
    opCol.appendChi ld(opColTxt);
    theSelect.appen dChild(opCol);
    <?php endforeach; ?>
    opCol.onselect = function(){
    if (this.getAttrib ute('value')==n ull || this.getAttribu te('value')=="" ){
    alert("Require field");
    }
    }
    span.appendChil d(theData);
    label.appendChi ld(span);
    label.appendChi ld(theSelect);
    p.appendChild(l abel);
    td.appendChild( p);
    row.appendChild (td);
    [/CODE]
    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").

    Code:
    if (this.getAttribute('value')==null || this.getAttribute('value')==""){
    		alert("Require field");
    		}
    }

    But it doesn;t work well, any idea??thanks for helping me..
  • rnd me
    Recognized Expert Contributor
    • Jun 2007
    • 427

    #2
    xbrowser onchange:

    Code:
    <select onchange"var ti=this.selectedIndex;var op=this.options; if(op[ti].value){ alert(op[ti].value); }">

    Comment

    • maminx
      New Member
      • Jul 2008
      • 77

      #3
      Originally posted by rnd me
      xbrowser onchange:

      Code:
      <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

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        onselect is only for text inputs and textareas. Use onchange on the select element, e.g.
        [code=javascript]theSelect.oncha nge = function() {
        if (this.value == "") alert("Required Field");
        }[/code]

        Comment

        Working...