/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] disabled=true on POST array

[code] function enableFields(num){
if (changeForm.elements[‘changeElementRow[‘+num+’]’].checked == true){
changeForm.elements[‘orderIt[‘+num+’]’].disabled = false;
changeForm.elements[‘lineAbove[‘+num+’]’].disabled = false;
changeForm.elements[‘lineBelow[‘+num+’]’].disabled=false;
}
else
{
changeForm.elements[‘orderIt[‘+num+’]’].disabled = true;
changeForm.elements[‘lineAbove[‘+num+’]’].disabled = true;
changeForm.elements[‘lineBelow[‘+num+’]’].disabled=true;
}
}
[/code]

[code=php]
<td>
<input type=”checkbox” disabled value=”1″ name=”lineAbove[<?php echo $row[‘page_pageElementId’] ?>]” <?php if($row[‘lineAbove’]!=0){ echo ‘ checked ‘;} ?>>
</td>
<td>
<input type=”checkbox” disabled value=”1″ name=”lineBelow[<?php echo $row[‘page_pageElementId’] ?>]” <?php if($row[‘lineBelow’]!=0){ echo ‘ checked ‘;} ?>>
</td>
<td>
<input type=”text” disabled value=”<?php echo $row[‘order’]; ?>” name=”orderIt[<?php echo $row[‘page_pageElementId’] ?>]” size=”3″>
</td>
<td>
input type=”checkbox” value=”1″ onclick=”enableFields(‘<?php echo $row[‘page_pageElementId’] ?>’);” name=”changeElementRow[<?php echo $row[‘page_pageElementId’] ?>]”>
</td>
[/code]

I’m sending the Javascript function a record ID from a database, and am telling it to disable/enable the corresponding fields. This works perfectly in firefox, but not IE.

In IE, the error produced is “‘changeForm.elements[…].checked’ is null or is not an object”

Why? Does anyone have a workaround?

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJul 09.2006 — Does anyone have a workaround?[/QUOTE]
No work-around required. It pays to be explicit. Your problem has to do with different browsers having different default object scoping.

[B]document[/B].changeForm.elements...
Copy linkTweet thisAlerts:
@sitehatcheryauthorJul 09.2006 — I started that way and the same result is produced.
Copy linkTweet thisAlerts:
@phpnoviceJul 09.2006 — Provide a live link and I'll run it through my JavaScript Debugger to tell you the exact problem.
Copy linkTweet thisAlerts:
@sitehatcheryauthorJul 10.2006 — I'd be more than happy to give you the link. However, it's an admin page which allows users to add and delete page elements, so I wish not to give it publicly. If you email me, I'll send you the link via email.
Copy linkTweet thisAlerts:
@sitehatcheryauthorJul 10.2006 — I've also tried this format:

document.forms['changeForm'].elements['orderIt['+num+']'].disabled = false;

Works in FF, but not IE

It seems that IE is having trouble reading the name of the element within the elements array, since the name of the element is itself an array. Is there another way to code this?
Copy linkTweet thisAlerts:
@sitehatcheryauthorJul 10.2006 — I also tried just concatonating the element name with the id instead of using an array. That doesn't work either.
Copy linkTweet thisAlerts:
@phpnoviceJul 10.2006 — Why are you talking about the [B]orderIt[/B] field when you said the original error message was on this line?

if (changeForm.elements['changeElementRow['+num+']'].checked == true){

If so, changing the other lines will do no good because IE will never get to those lines.

...and can't email you because your profile says you have requested no emails.
Copy linkTweet thisAlerts:
@sitehatcheryauthorJul 10.2006 — Oh, didn't realize I had it set like that. Anyway, I figured it out by changing the code to this, which works in IE and FF:
<i>
</i>function enableFields(num){
if (document.getElementById('changeElementRow['+num+']').checked == true){
document.getElementById('orderIt['+num+']').disabled = false;
document.getElementById('lineAbove['+num+']').disabled = false;
document.getElementById('lineBelow['+num+']').disabled=false;
}
else
{
document.getElementById('orderIt['+num+']').disabled = true;
document.getElementById('lineAbove['+num+']').disabled = true;
document.getElementById('lineBelow['+num+']').disabled=true;
}
}
×

Success!

Help @sitehatchery 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.18,
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,
)...