/    Sign up×
Community /Pin to ProfileBookmark

dynamic text box as response to a checkbox click

HI eyeryone,
My problem is that i have a check box and i want to display new text boxez when the check box is clicked.
example:

text box 1
text box 2
text
text box 3
radio button
(If radio button is clicked i want my new text box 5 here)
text box 4
button

more on why i want it

are you a citizen of US “yes” “no”
if user clicks “yes” then there should be a new text saying
“what is your SSN” and a text box for user to input SSN

the other content on the page should remain unchanged
I hope you understand my problem.

Thank you,
Kalyan

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CharlesSep 22.2004 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<meta name="Content-Style-Type" content="text/css">

<title>Example</title>

<style type="text/css">

<!--

form {width:10em}

fieldset {padding:1ex}

label {display:block; margin:1em 0}

button {display:block; margin:auto}

.hidden {display:none}

-->

</style>

</head>

<body onload="document.getElementById('other').className = 'hidden'">

<form action="someScript.pl">

<fieldset>

<legend>Example</legend>

<label>Name <input type="text"></label>

<label>Address <input type="text"></label>

<label><input type="checkbox" onclick="document.getElementById('other').className = this.checked ? '' : 'hidden'"> Other?</label>

<label id="other">Other <input type="text"></label>

<button type="submit">Submit</button>

</fieldset>

</form>

</body>

</html>[/font]
Copy linkTweet thisAlerts:
@Warren86Sep 22.2004 — k_kyss:

Try this:

<HTML>

<Head>

<Script Language=JavaScript>

function getSSN(isForm){

isForm.SSN.value = "";
isForm.SSN.disabled = false;
isForm.SSN.focus();
alert('Please enter your Social Security Number');
}

function resetForm(isForm){

isForm.reset();
isForm.askCitizen[0].checked = true;
initForm(isForm);
}

function unDo(isForm){

isForm.askCitizen[0].checked = true;
initForm(isForm);
}


function initForm(isForm){

isForm.SSN.value = "000-00-0000";
isForm.SSN.disabled = true;
isForm.country.value = "USA";
isForm.personal.focus();
}


</Script>

</Head>

<Body>

<form name='Form1'>

Name <input name='personal' size=25><br><br>

Address <input name='address' size=30><br><br>

City <input name='city' size=15> State <input name='state' size=2><br><br>

Zip Code <input name='zip' size=4>&nbsp;&nbsp; Country <input name='country' size=15><br><br>

Are you a U.S. citizen?

<input type=radio name='askCitizen' checked onClick="unDo(Form1)"> No

<input type=radio name='askCitizen' onClick="getSSN(Form1)"> Yes <br>

SSN <input name='SSN' size=9><br><br>

<input type=submit value="Submit Form">

<input type=button value="Reset" onClick="resetForm(Form1)">

</form>

<Script>

initForm(Form1);

</Script>

</Body>

</HTML>
×

Success!

Help @k_kyss spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...