Web Analytics Made Easy -
StatCounter html formselect and textfield show with JS - CodingForum

Announcement

Collapse
No announcement yet.

html formselect and textfield show with JS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • html formselect and textfield show with JS

    hey i got this select field with 3things in it and i want to make some functions in javascript so when i select one some textfields will show depending on which one i choose and when im choosing one without the need of textfields they should be removed if there is any textfield on the screen


    Thanks in advance

  • #2
    so in your select statement have a onChange event call a function and based on the select statement's value change the innerHTML of your display element.

    Comment


    • #3
      thanks but i was looking for some code to make the funtion but with some time i found it out if any1 is interestet in it is like this
      Code:
      function txtch()
      {
      if(document.getElementById("mySelect").value == "chpass"){
      
      document.getElementById('cont').innerHTML = 'Password: <input type=\"password\" name=\"nup\"><br />';
      
      }
      
      else if(document.getElementById("mySelect").value == "newu"){
      
      document.getElementById('cont').innerHTML = 'Username: <input type=\"text\" name=\"nun\"><br />Password: <input type=\"password\" name=\"nup\"><br />';
      
      }
      else{
      document.getElementById('cont').innerHTML ='';
      
      
      }
      }

      and the html part :
      Code:
      Choose an option: <select name="valg" id="mySelect" onchange="txtch()">
          <option value="delete" selected="selected">Delete</option>
          <option value="chpass">Change password</option>
          <option value="newu">Create new user</option>
      </select><br />
      <div id="cont">
      
      </div>
      (remember to put the select in a form ^^ )

      Comment

      Working...
      X