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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Making textboxes appear on a webpage using javascript

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


    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, Registered Users 2 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, Registered Users 2 Posts: 2,325 ✭✭✭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