/    Sign up×
Community /Pin to ProfileBookmark

Java script text box

what is the error in following code.? The desired output is to show the text box when the option ‘TATA’ is clicked.. Help..

<html>
<head><title>sam</title>
</head>

<script language=”javascript”>
<!–
function cho(a)
{
if(a==”TATA”)
{
<input type=”text” value=”other”>
}
}
//–>
</script>
<body>

<form>
<select name=”cars”>
<option>BENZ
<option>FERRARI
<option>HONDA
<option>TATA
<input type=”button” value=”ok” onClick=”cho(this.form.cars)”>
</form>

</select>
</body>
</html>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@magwarFeb 05.2010 — hi , i'm newbie , i have this way ?

<html>

<head><title>sam</title>

</head>

<script type = "text/javascript">

function cho()

{

var b = document.getElementById("TATA")

if(b.selected)

{

document.getElementById("output").innerHTML = '<input type="text" value = "TATA choiced"></input>'

}

}

</script>

<body>

<form>

<select name="cars">

<option selected>BENZ

<option>FERRARI

<option>HONDA

<option id="TATA">TATA

</select>

<input type="button" value="ok" onClick="cho()">

</form>

<div id="output"></div>

</body>

</html>
Copy linkTweet thisAlerts:
@Gozzy82Feb 05.2010 — magwar's function works fine you might not want to add the id to the option but to the select and add a change event to the select



[CODE]

<html>
<head><title>sam</title>
</head>

<script type = "text/javascript">
function cho()
{
var b = document.getElementById("cars");

if(b.options[b.selectedIndex].text == 'TATA')
{
document.getElementById("output").innerHTML = '<input type="text" value = "TATA choiced" />';
}
}
</script>
<body>

<form>
<select name="cars" id="cars" onchange="cho()">
<option selected>BENZ</option>
<option>FERRARI</option>
<option>HONDA</option>
<option>TATA</option>
</select>
<input type="button" value="ok" onClick="cho()">
</form>
<div id="output"></div>
</body>
</html>

[/CODE]
Copy linkTweet thisAlerts:
@Gozzy82Feb 05.2010 — erm the <script type="text/javascript"></script> should be in between the <head></head> tags
×

Success!

Help @wlogeshwaran 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.15,
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,
)...