...

View Full Version : onClick problem with IE



creospace
05-12-2006, 12:17 PM
Hi,

I have a very simple problem, i'm doing a form of which i want some fields to be enabled/diabled based on selection. Got it working fantastic in FF but not IE.

I wonder if anyone can help

Heres the examples (i've cut out the irelevant HTML) :


function drinksonlyon()
{
document.forma.fldHead.disabled=true;
document.forma.fldVegan.disabled=true;
document.forma.fldGluten.disabled=true;
}

<OPTION VALUE='999' onclick="drinksonlyon (); "/>Blah </OPTION>

<input type="text" name="fldHead" id="fldHead" tabindex="15" size='5' />

OR


<input type=radio name="fldblah" id="fldblah" onclick="javascript:document.forma.fldblah.disabled=false"/> No<br />

<textarea name="fldInvoice" id="fldblah" tabindex="9" cols=30 rows=5 disabled></textarea>

If anyone can point me in the right direction i'd be very happy.

Thanks

Gary

Kor
05-12-2006, 12:34 PM
1. Use onchange event aplied on SELECT control

<select onchange="this.value=='999'?drinksonlyon ():null">
...
<option value='999'>Blah </option>

IE does not support onclick upon option object.

2. To enable a disabled element, rather use DOM:

object.removeAttribute('disabled')

creospace
05-12-2006, 01:43 PM
ok how does it work with multiple and differing selections? Maybe I should of posted the full thing first :) You can see what i'm wanting to do as different choices need different fields.


<div>
<label for="fldBuffet">Buffet:</label>
<select name="fldBuffet" id="sBuffet" tabindex="14">
<option >SELECT</option>
<OPTION VALUE='5' onclick="drinksonlyoff ();">Business Buffet</OPTION>
<OPTION VALUE='31' onclick="teacoffee(); ">Tea &amp; Coffee with biscuits </OPTION>
<OPTION VALUE='37' onclick="drinksonlyoff ();">Members Tea Menu 4</OPTION>
<OPTION VALUE='999' onclick="drinksonlyon (); ">Drinks Only - see below</OPTION>
</select>
</div>

I've never really dabbled with java of any sort before, other than ready made scripts.

Thanks

Gary

creospace
05-12-2006, 01:50 PM
2. To enable a disabled element, rather use DOM:

object.removeAttribute('disabled')


Sorry this doesn't mean anything to me - i know what i know and there's where it stops! could you show me how it would look in the radio button and the text area what it enables?

Thanks (Multum esc)

Gary :)

Kor
05-12-2006, 02:27 PM
Here'a simple example how setAttribute() and removeAttribute() work:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function enableField(f,v){
v.length<1?f['bttnsubmit'].setAttribute('disabled',true):f['bttnsubmit'].removeAttribute('disabled')
}
</script>
</head>
<body>
<form>
<textarea onkeyup="enableField(this.form,this.value)"></textarea>
<br>
<input type="submit" value="Submit" name="">
</form>
</body>
</html>

creospace
05-12-2006, 03:21 PM
You're obviously far more clever than I because that makes absolutley no sense :( Remember I know absolutely nothing about this stuff, I was amazed when what i did worked in firefox!

Maybe you know a good site where I can start from scratch. DOM for Dummies .com or something?

If anyone can layout what is neeed using the fld names and ID's that i've been using in my code than it would make more sense becasue i could follow it.

I dont even know which parts I am to put my own stuff in or keep it as is? :(

Many thanks

Gary

Kor
05-12-2006, 03:43 PM
Some of the online tutorials for javascript/DOM are really good:

http://www.w3schools.com/js/default.asp
http://www.howtocreate.co.uk/tutorials/javascript/introduction
http://www.quirksmode.org/

The standard javascript and DOM are:

EcmaScript
http://www.ecma-international.org/publications/standards/Ecma-327.htm
w3c DOM
http://www.w3.org/TR/DOM-Level-2-Core/core.html

Unfortunately javascript/DOM, even now is a stabile language, is not full standardized, usually browsers have some particular methods/behaviours. Good tutorials show the most important differences (mainly between IE and Moz)
Edit/Delete Message



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum