PDA

View Full Version : Javascript problem


chaosweapon
21-02-2008, 11:46 AM
First of all here's the code:

<script type="text/javascript">
function disable_input(input,choice)
{
(this.value == choice)? document.getElementById(input).disabled=false : document.getElementById(input).disabled=true;
}
</script>

<form>
<select name="action" id="action" onChange="disable_input('member','give')">
<option value="discard">Discard</option>
<option value="give">Give to</option>
</select>
<input disabled type="text" id="member" name="member">
</form>


The script is supposed to enable input only when 'Give to' is selected. Can somebody explain what I'm doing wrong?

hex4
21-02-2008, 10:13 PM
<script type="text/javascript">
function disable_input(control, controlvalue)
{
if (document.getElementById(control).options[document.getElementById(control).selectedIndex].value == controlvalue) { document.getElementById("member").enabled = false; };

}
</script>

<form>
<select name="action" id="action" onchange="disable_input(this.id, this.value)">
<option>Discard</option>
<option>Go To</option>
</select>
<input type="text" id="member" name="member" />
</form>

jekk qed tuza firefox, installa Firebug, bit ram hungry imma jghinek hafna fuq errors ekk

chaosweapon
22-02-2008, 08:24 AM
jekk qed tuza firefox, installa Firebug, bit ram hungry imma jghinek hafna fuq errors ekk
That code is not working either.

hex4
22-02-2008, 08:32 AM
Change document.getElementById("member").enabled = false; to document.getElementById("member").disabled = true;

<script type="text/javascript">
function disable_input(control, controlvalue)
{
if (document.getElementById(control).options[document.getElementById(control).selectedIndex].value == controlvalue)
{
document.getElementById("member").disabled = true;
}

}
</script>

<form>
<select name="action" id="action" onchange="disable_input(this.id, this.value)">
<option>Discard</option>
<option>Go To</option>
</select>
<input type="text" id="member" name="member" />
</form>


ghanda tahdem hekk

chaosweapon
22-02-2008, 08:37 AM
Does not work as well. It doesn't re-enable input. Anyway I got the solution now. I just replaced the this part.


<script type="text/javascript">
function disable_input(input,dropdown,choice)
{
(document.getElementById(dropdown).value == choice)? document.getElementById(input).disabled=false : document.getElementById(input).disabled=true;
}
</script>
<form>
<select name="action" id="action" onChange="disable_input('member',this.id,'give')">
<option value="discard">Discard</option>
<option value="give">Give to</option>
</select>
<input disabled type="text" id="member" name="member">
</form>

hex4
22-02-2008, 04:47 PM
kollox bl-ezatt trid int madonna...

mux kemm taghmel else .disabled = false; ...

jekk tnehhi l value="" min go l-option tag il value tista ssibu bil metodu li urejtek jien... tintuza jekk specjalment ha ttella l-option tags min god database

chaosweapon
22-02-2008, 05:01 PM
kollox bl-ezatt trid int madonna...

mux kemm taghmel else .disabled = false; ...

jekk tnehhi l value="" min go l-option tag il value tista ssibu bil metodu li urejtek jien... tintuza jekk specjalment ha ttella l-option tags min god database
As I said, I got the solution but thanks for your help. I can't remove the value tag coz of languages. This code is for the Triple Triad mod I'm writing right now and according to the phpbb3 guidelines I must use a template variable for each phrase.