Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to return a value to a document.getElementById()

    Hi all..what i'm trying to do is change the backgroundColor of my input text with js..

    this the js part
    Code:
    function CreateCFormArray(){
    	var y=document.getElementsByName("cf");
    	//alert(y[0].value);
            for(i = 0; i < y.length; i++) {
    			if(y[i].id=='cf1' && y[i].value=='0'){
                                 changeCssProp(name);                            
    			}
    			if(y[i].id=='cf2' && y[i].value=='0'){
                                 changeCssProp(phone);
    			}							
            }	
    }
    var	thefield;
    function changeCssProp(thefield) {
    document.getElementById(thefield).style.backgroundColor="#FF0000";
    }
    and this is the html part

    Code:
    <form id="form1" name="form1" method="post" action="">
      <table width="100%" border="2" cellspacing="0" cellpadding="0">
        <tr>
          <td>name</td>
          <td>
    		  <label>
    			<input type="text" name="name" id="name" />
    		  </label>
    	  </td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>phone</td>
          <td>
    		  <label>
    			<input type="text" name="phone" id="phone" />
    		  </label>
    	  </td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>
    		  <label>
    			<input type="button" name="Submit" value="Submit" onclick="CreateCFormArray()" />
    		  </label>
    	  </td>
          <td>
    		  <input name="cf" type="hidden" id="cf1" value="0" />
    		  <input name="cf" type="hidden" id="cf2" value="0" />
    	  </td>
          <td>&nbsp;</td>
        </tr>
      </table>
    </form>
    basicly what the script do is to check the hidden field cf with value of '0' if found it will execute changeCssProp(thefield)..but the problem is js return error of document.getElementById(thefield) is null
    can someone help me with..thanking you all in advance for reviewing my

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    if(y[i].id=='cf1' && y[i].value=='0'){
                                 changeCssProp('name');                            
    			}
    			if(y[i].id=='cf2' && y[i].value=='0'){
                                 changeCssProp('phone');
    			}
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •