/    Sign up×
Community /Pin to ProfileBookmark

problem enabling and disabling form elements works in FF but not IE 7

Well i hate javascript lol or at least i do until i get used to it

Im using the following

[CODE]<script language=”javascript”>
/* Script for disabling form elements and only enabling them when the select menu is changed for product 2 */

function enableFielda()
{
document.step2.product2a.disabled=false;
document.step2.product2b.disabled=false;
document.step2.product2c.disabled=false;
document.step2.product2d.disabled=false;
document.step2.product2e.disabled=false;
document.step2.product2f.disabled=false;
}

/* Script for disabling form elements when the select menu is changed to a none item */

function disableFielda()
{
document.step2.product2a.disabled=true;
document.step2.product2b.disabled=true;
document.step2.product2c.disabled=true;
document.step2.product2d.disabled=true;
document.step2.product2e.disabled=true;
document.step2.product2f.disabled=true;
}

/* Script for disabling form elements and only enabling them when the select menu is changed for product 3 */

function enableFieldb()
{
document.step2.product3a.disabled=false;
document.step2.product3b.disabled=false;
document.step2.product3c.disabled=false;
document.step2.product3d.disabled=false;
document.step2.product3e.disabled=false;
document.step2.product3f.disabled=false;
}

/* Script for disabling form elements when the select menu is changed to a none item */

function disableFieldb()
{
document.step2.product3a.disabled=true;
document.step2.product3b.disabled=true;
document.step2.product3c.disabled=true;
document.step2.product3d.disabled=true;
document.step2.product3e.disabled=true;
document.step2.product3f.disabled=true;
}

</script>
[/CODE]

This is the code im using on a form element

[CODE]<select size=”1″ name=”productpr2″ style=”color: #2D8458;”>
<option selected onChange=”javascript:disableFielda()”></option>
<option value=”Large Figure, Pants:15.00″ onChange=”javascript:enableFielda()”>Lg Figure (Pants) $15</option>
<option value=”Small Figure, Pants:13.00″ onChange=”javascript:enableFielda()”>Sm Figure (Pants) $13</option>
<option value=”Large Figure, Dress:15.00″ onChange=”javascript:enableFielda()”>Lg Figure (Dress) $15</option>
<option value=”Small Figure, Dress:13.00″ onChange=”javascript:enableFielda()”>Sm Figure (Dress) $13</option>
<option value=”Dog:5.00″ onChange=”javascript:enableFielda()”>Dog $5.00</option>
<option value=”Cat:5.00″ onChange=”javascript:enableFielda()”>Cat $5.00</option>
</select> [/CODE]

The whole idea is that several form elements are enabled when someone chooses a value from a drop down list and then disabled if they chose the blank option in that drop down field

However this works in firefox but not in IE 7 so what am i doing wrong

can anyone explain this to me??

to post a comment
JavaScript

17 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 18.2007 — option does not fire events in IE, use onchange in the select.

Secondly an option can not be disabled in IE.
Copy linkTweet thisAlerts:
@BWWebDesignsauthorSep 18.2007 — none of that was helpful in any way, onchange didnt work in firefox or IE7
Copy linkTweet thisAlerts:
@KorSep 18.2007 — none of that was helpful in any way, onchange didnt work in firefox or IE7[/QUOTE]
What's your new code? [B]Fang[/B] has given you the correct answer, it depends on what you have understood.
Copy linkTweet thisAlerts:
@BWWebDesignsauthorSep 19.2007 — i am using the same code i origionally did but changing the onClick to onChange

Can someone take the code i posted and show modifications so i can understand it better??
Copy linkTweet thisAlerts:
@FangSep 19.2007 — &lt;select onchange="(this.value!=0)? enableFielda() : disableFielda();" size="1" name="productpr2" style="color: #2D8458;"&gt;
&lt;option value="0" selected&gt;&lt;/option&gt;
&lt;option value="1"&gt;Lg Figure (Pants) $15&lt;/option&gt;
&lt;option value="2"&gt;Sm Figure (Pants) $13&lt;/option&gt;
&lt;option value="3"&gt;Lg Figure (Dress) $15&lt;/option&gt;
&lt;option value="4"&gt;Sm Figure (Dress) $13&lt;/option&gt;
&lt;option value="5"&gt;Dog $5.00&lt;/option&gt;
&lt;option value="6"&gt;Cat $5.00&lt;/option&gt;
Copy linkTweet thisAlerts:
@BWWebDesignsauthorSep 19.2007 — thanks for the input i actually solved this about 30 mins ago by using teh following

[CODE]<script language="javascript">
function enableFielda(SelectValue){
//if (document.getElementByName("productpr2").value=='')
if (SelectValue=='') {
document.getElementById("product2a").disabled=true;
document.getElementById("product2b").disabled=true;
document.getElementById("product2c").disabled=true;
document.getElementById("product2d").disabled=true;
document.getElementById("product2e").disabled=true;
document.getElementById("product2f").disabled=true;
} else {
document.getElementById("product2a").disabled=false;
document.getElementById("product2b").disabled=false;
document.getElementById("product2c").disabled=false;
document.getElementById("product2d").disabled=false;
document.getElementById("product2e").disabled=false;
document.getElementById("product2f").disabled=false;
}
}
</script>[/CODE]



and

[CODE]<select size="1" name="productpr2" style="color: #2D8458;" onChange="javascript:enableFielda(this.value)">
<option selected></option>
<option value="Large Figure, Pants:15.00">Lg Figure (Pants) $15</option>
<option value="Small Figure, Pants:13.00">Sm Figure (Pants) $13</option>
<option value="Large Figure, Dress:15.00">Lg Figure (Dress) $15</option>
<option value="Small Figure, Dress:13.00">Sm Figure (Dress) $13</option>
<option value="Dog:5.00">Dog $5.00</option>
<option value="Cat:5.00">Cat $5.00</option>
</select> [/CODE]


it seems to work fine, i couldnt have changed the value parameters of the select statement the way you did by numbering them anyway as the values passed need to be the text they are

But its working now in IE just not in firefox now lol

Any advice
Copy linkTweet thisAlerts:
@FangSep 19.2007 — Should work, did you reload the script in the browser?
Copy linkTweet thisAlerts:
@BWWebDesignsauthorSep 19.2007 — yeah i figured out what was going wrong, for some reason the getelementbyid thingy wasnt working in firefox so i just modified the code to check if it was IE and if it was to display one code and if it wasnt to display the other and it seems to work on several different browsers i ahve tried now

[CODE]<script language="javascript">
//if (is_ie4up) {
if (navigator.appName == "Internet Explorer") {
/* Script for disabling form elements and only enabling them when the select menu is changed for product 2 */

function enableFielda(SelectValue){
//if (document.getElementByName("productpr2").value=='')
if (SelectValue=='') {
document.getElementById("product2a").disabled=true;
document.getElementById("product2b").disabled=true;
document.getElementById("product2c").disabled=true;
document.getElementById("product2d").disabled=true;
document.getElementById("product2e").disabled=true;
document.getElementById("product2f").disabled=true;
} else {
document.getElementById("product2a").disabled=false;
document.getElementById("product2b").disabled=false;
document.getElementById("product2c").disabled=false;
document.getElementById("product2d").disabled=false;
document.getElementById("product2e").disabled=false;
document.getElementById("product2f").disabled=false;
}
}

function enableFieldb(SelectValue){
//if (document.getElementByName("productpr2").value=='')
if (SelectValue=='') {
document.getElementById("product3a").disabled=true;
document.getElementById("product3b").disabled=true;
document.getElementById("product3c").disabled=true;
document.getElementById("product3d").disabled=true;
document.getElementById("product3e").disabled=true;
document.getElementById("product3f").disabled=true;
} else {
document.getElementById("product3a").disabled=false;
document.getElementById("product3b").disabled=false;
document.getElementById("product3c").disabled=false;
document.getElementById("product3d").disabled=false;
document.getElementById("product3e").disabled=false;
document.getElementById("product3f").disabled=false;
}
}
} else {
/* Script for disabling form elements and only enabling them when the select menu is changed for product 2 */

function enableFielda(SelectValue){
//if (document.getElementByName("productpr2").value=='')
if (SelectValue=='') {
document.step2.product2a.disabled=true;
document.step2.product2b.disabled=true;
document.step2.product2c.disabled=true;
document.step2.product2d.disabled=true;
document.step2.product2e.disabled=true;
document.step2.product2f.disabled=true;
} else {
document.step2.product2a.disabled=false;
document.step2.product2b.disabled=false;
document.step2.product2c.disabled=false;
document.step2.product2d.disabled=false;
document.step2.product2d.disabled=false;
document.step2.product2f.disabled=false;
}
}

function enableFieldb(SelectValue){
//if (document.getElementByName("productpr2").value=='')
if (SelectValue=='') {
document.step2.product3a.disabled=true;
document.step2.product3b.disabled=true;
document.step2.product3c.disabled=true;
document.step2.product3d.disabled=true;
document.step2.product3e.disabled=true;
document.step2.product3f.disabled=true;
} else {
document.step2.product3a.disabled=false;
document.step2.product3b.disabled=false;
document.step2.product3c.disabled=false;
document.step2.product3d.disabled=false;
document.step2.product3e.disabled=false;
document.step2.product3f.disabled=false;
}
}
}
</script>[/CODE]
Copy linkTweet thisAlerts:
@FangSep 19.2007 — Looks like your [I]id[/I]'s are not unique, which is invalid.
Copy linkTweet thisAlerts:
@BWWebDesignsauthorSep 19.2007 — what about my ids are not unique??

they all start with product2 or product3 and are followed by a,b,c,d,e or f and only one of each with the same name id etc
Copy linkTweet thisAlerts:
@KravvitzSep 19.2007 — Are those really IDs and not names? IE wrongly will return an element with the name set to the value of the ID it's looking if no element has the ID.
Copy linkTweet thisAlerts:
@KorSep 19.2007 — [B]id[/B] is not the same with [B]name[/B]. If no id, IE takes the name as id, but this is an incorrect approach.
Copy linkTweet thisAlerts:
@BWWebDesignsauthorSep 19.2007 — well what would stop this from working? as it works in different browsers and has no problems so far? apart from it not being the correct way of doing things is there any real problem that will be caused by doing this
Copy linkTweet thisAlerts:
@WebnerdSep 19.2007 — is there any real problem that will be caused by doing this[/quote]

Yes, you could become eternally stupid and have conflicts with other developers who do it the "right way".
Copy linkTweet thisAlerts:
@BWWebDesignsauthorSep 19.2007 — well right or wrong, it works for now and thats all that matters, i know in future the correct way of doing it but for now ill leave it working as is
Copy linkTweet thisAlerts:
@KorSep 19.2007 — Yes, you could become eternally stupid and have conflicts with other developers who do it the "right way".[/QUOTE]

[B]Webnerd[/B], I guess you must apologize [B]BWWebDesigns[/B]. And, please, I'd like you not to offend the beginners, nor other people around, nor other people anywhere else.
Copy linkTweet thisAlerts:
@WebnerdSep 20.2007 — I apologize if my remarks were a bit harsh. I'll try to make my responses and help more direct to the problems and not be so judgmental. I was a beginner one day also so I understand the process of learning.
×

Success!

Help @BWWebDesigns 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 6.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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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