Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Making textboxes appear on a webpage using javascript

Options
  • 23-03-2005 2:05pm
    #1
    Registered Users Posts: 2,320 ✭✭✭


    hey guys just a quickie,

    I want textboxes to appear only when the user clicks a checkbox. The code i have doesnt work (it never does ;) )

    javascript
    function searchAuthor() {
    
    	var checkbox = window.document.form2.check_1;
    
    	if (checkbox == false) {
    		window.document.writeln("<tr><td>Please enter the author of the book you wish to search for:</td>")
    		window.document.writeln("<td><INPUT TYPE=text ID=author NAME=author></td></tr>")
    		}
    
    	}
    

    the form
    <FORM NAME=form METHOD=get ACTION="./myass.htm" onSubmit="return check()">
    <TABLE>
    <tr>
    	<td>
    		Please enter the title of the book you wish to search for:
    	</td>
    	<td>
    		<INPUT TYPE=text ID=title NAME=title>
    	</td>
    </tr>
    <tr><td>
    <input type="checkbox" name ="check_1" onClick="searchAuthor();">Search by Author
    </td></tr>
    <tr>
    	<td>
    		&nbsp
    	</td>
    	<td>
    		<INPUT id=reset type=reset value=Reset name=reset>
    		<INPUT id=submit type=submit value=Submit name=submit>
    	</td>
    </tr>
    </TABLE>
    </FORM>
    

    Any ideas?


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Try this:

    (Haven't tested it)


    HTML:
    <FORM NAME=form METHOD=get ACTION="./myass.htm" onSubmit="return check()">
    <TABLE>
    <tr>
    	<td>
    		Please enter the title of the book you wish to search for:
    	</td>
    	<td>
    		<INPUT TYPE=text ID=title NAME=title>
    	</td>
    </tr>
    <tr><td>
    <input type="checkbox" id="check_1" name ="check_1" onClick="searchAuthor();">Search by Author
    </td></tr>
    <tr>
    	<td>
    		<div id="textboxen" style="display: none">
                        Please enter the author of the book you wish to search for:
    		    <INPUT TYPE=text ID=author NAME=author>
                   </div>
    	</td>
    	<td>
    		<INPUT id=reset type=reset value=Reset name=reset>
    		<INPUT id=submit type=submit value=Submit name=submit>
    	</td>
    </tr>
    </TABLE>
    </FORM>
    

    Javascript:
    function searchAuthor() {
       if(document.getElementById){
    	var textboxes = document.getElementById("textboxen");
            var chkbx = document.getElementById("check_1");
           
             if(chkbx.checked = true)
                 textboxes.style.display = "block";
             else
                 textboxes.style.display = "none;
    	
       }
    }
    


  • Registered Users Posts: 2,320 ✭✭✭Q_Ball


    its not working.

    when i enter the page i get an unterminated string constant error. Then when i check the box i get an object expected error.

    cheers for the help!


Advertisement