/    Sign up×
Community /Pin to ProfileBookmark

collapsible form problem

Hi im having problem with this javaScript, in IExplorer didnt work, in firefox works perfect..
the idea is that when you click in the “otra” option the div below appear, and when you select another diferent from “otra” the div dissapear….

im new in java script i beggin learn a few days ago because in my work i need it, i hope you can help me….

my english is not the best, i hope you can understand.

thanks
Att:
Alejandro Herrera

[code]

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Adiohawk</title>

</head>
<body>

<form action=”#” method=”post”>
<script type=”text/javascript”>
function toggle(sDivId) {
var oDiv = document.getElementById(sDivId);
oDiv.style.display = (oDiv.style.display == “none”) ? “block” : “block”;
};

function toggle2(sDivId) {
var oDiv = document.getElementById(sDivId);
oDiv.style.display = (oDiv.style.display == “block”) ? “none” : “none”;
}

</script>

<select name=”universidad” class=”input2″>

<option value=”” selected=”selected” ></option>

<optgroup label=”Bogota” >
<option onclick=”toggle2(‘divContent2’)” value=”impsem 1″>impsem 1</option>
<option onclick=”toggle2(‘divContent2’)” value=”impsem 2″>impsem 2</option>
<option onclick=”toggle2(‘divContent2’)” value=”impsem 3″>impsem 3</option>

</optgroup>

<optgroup label=”Medellin”>
<option onclick=”toggle2(‘divContent2’)” value=”impsem 4″ >impsem 4</option>
</optgroup>
<option onclick=”toggle(‘divContent2’)” value=”otra” >Otra</option>

</select>

<div id=”divContent2″ style=”padding:0px; display:none”>
<input type=”text” name=”otra” />

</div>

</form>

</body>
</html>

[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceMay 05.2006 — [code=html]<form action="#" method="post">
<p><select name="universidad" class="input2"
onchange="return toggleDiv(this, 'divContent2')">
<option value="">[select one]</option>
<optgroup label="Bogota" >
<option value="impsem 1">impsem 1</option>
<option value="impsem 2">impsem 2</option>
<option value="impsem 3">impsem 3</option>
</optgroup>
<optgroup label="Medellin">
<option value="impsem 4">impsem 4</option>
</optgroup>
<option value="otra">Otra</option>
</select></p>
<div id="divContent2" style="padding:0px;">
<input type="text" name="otra">
</div>
</form>

<script type="text/javascript">
<!--//
function toggleDiv(oSel, sDivId) {
var oDiv = document.getElementById(sDivId);
if(oSel.options[oSel.selectedIndex].value == "otra") {
oDiv.style.display = "block";
} else {
oDiv.style.display = "none";
}
return true;
}
toggleDiv(document.forms[0].elements["universidad"], "divContent2");
//-->
</script>[/code]
Copy linkTweet thisAlerts:
@adiohawkauthorMay 05.2006 — Thanks a lot phpnovice.....


att:

Alejandro Herrera
Copy linkTweet thisAlerts:
@phpnoviceMay 05.2006 — You're very welcome.

Cheers.
×

Success!

Help @adiohawk 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.2,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...