/    Sign up×
Community /Pin to ProfileBookmark

javascript not handling select value correctly

hi, not sure why both IF’s execute… try out this code, and let me know what you think … thanks !!

<HTML>
<HEAD>
<SCRIPT language=”javascript”>
function activator(row) {
var id = new String();
var sVal = new String();
id = “t_active” + row;
var oObj = document.getElementById(id);
var sVal = oObj.value;
alert(sVal);

if (sVal=”N”) {
alert(“disable”);
id = “t_act” + row;
var oTd = document.getElementById(id);
oTd.disabled = true;

id = “t_rpt” + row;
var oSel = document.getElementById(id);
oSel.disabled = true;
}

else if (sVal=”Y”) {
alert(“enable”);
id = “t_act” + row;
var oTd = document.getElementById(id);
oTd.disabled = false;

id = “t_rpt” + row;
var oSel = document.getElementById(id);
oSel.disabled = false;
}

}

function onsave() {
var len = document.forms[0].elements.length;
for (var i=1; i <= len; i++) {
if ( document.forms[0].elements[i] != null ) {
document.forms[0].elements[i].disabled = false;
}
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name=form1 action=”” method=”post”>
<TABLE border=0 cellPadding=4 cellSpacing=0 width=”80%” align=center>
<TR><TD>Advertiser</TD>
<TD>Subscribe?</TD>
<TD>Variable1</TD>
<TD>Variable2</TD>
</TR>
<TR>
<TD>adv1</TD>
<TD>
<select name=”t_active” id=”t_active1″ onchange=”activator(1);”>
<option value=”Y”>Yes</option>
<option value=”N”>No</option>
</select>
</TD>
<TD><INPUT type=text name=t_rpt id=”t_rpt1″ value=”this is t_rpt1″></TD>
<TD><INPUT type=text name=t_act id=”t_act1″ value=”this is t_act1″></TD>
</TABLE>
<BR><BR><BR>
<center>
<INPUT name=cmdsave class=”sbutton” type=button value=”Reset” onClick=”onsave();”>
</FORM>
</BODY>
</HTML>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@tabzterSep 09.2005 — 
change:

if (sVal="N") to [B]if (sVal=="N")[/B]

and

if (sVal="Y") to [B]if (sVal=="Y")[/B]

thats it.
[/QUOTE]
?

Ps. This code is a bit sloppy. Too many unneccessary actions.

For Example you dont need [B]activator([U]1[/U])[/B] or [B]id = "t_active" + row;[/B]

just keep it as [I]activator() and id="t_active"[/I].


btw: change <input name=cmdsave... type=button...> to <input type="reset"...>

[U]ALWAYS USE QUOTATION MARKS[/U]
×

Success!

Help @brynbstn 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.17,
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,
)...