Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Making textboxes appear on a webpage using javascript

  • 23-03-2005 02:05PM
    #1
    Registered Users, Registered Users 2 Posts: 2,323 ✭✭✭


    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,173 ✭✭✭✭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,323 ✭✭✭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