Closed Thread Icon

Topic awaiting preservation: Help with javascript form management on the fly!! (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=26511" title="Pages that link to Topic awaiting preservation: Help with javascript form management  on the fly!! (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Help with javascript form management  on the fly!! <span class="small">(Page 1 of 1)</span>\

 
NeoNeo
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Aug 2005

posted posted 08-23-2005 00:32

Is there a way using javascript to change the display of a form after it as been rendered?

I won?t to remove a checkbox on a form if a certain condition is true.

Since this case is not the norm, the default rendering displays the checkbox even though it?s not a valid selection.

And the check I guess would have to come when the link to display the form is clicked.

Any ideas??


Thanks

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 08-23-2005 08:10

I have no idea

NeoNeo
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2005

posted posted 08-23-2005 20:03

i just created a function that gets the elementsid from the form and set that to none.

code
document.getElementById('checkbox').style.display = 'none';

================================================================

Does anyone know how to set a radio button to checked using something like above.

================================================================

I have treid doing this with no success
code
document.getElementById('checkbox2').checked == true;

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-23-2005 20:32

document.getElementById('checkbox2').checked == true;

That == should be a single =. (== does a comparison and has no side effect.)

You might also consider .disabled = true instead of making it invisible.


 

NeoNeo
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2005

posted posted 08-23-2005 21:23

Thanks for pointing that out.

I used the single = and the checkbox is still not checked when the form displays.

when i tried the .disabled=true checkbox2 was disabled. But this is not what i won't to do with checkbox2.


What i have done is hide checkbox1 if a condition is true. Checkbox1 was checked by default.
Now that it's hidden checkbox2 is now the first checkbox, and i want that to become checked by default.

code
if(...)
{
document.getElementById('checkbox1').style.display = 'none';
document.getElementById('checkbox2').checked=true;
}
else
{
document.getElementById('updateType0').style.display = '';
}

i also tried using the form name like so: form.checkbox2.checked = true;
I am i doing something wrong here?
The element does change if i use .disabled. is .checked even valid?

NeoNeo
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2005

posted posted 08-23-2005 23:26

FINALLY!!
I went something different all together.
Lessons learned; the first idea isn't always possible. Now to tackle the styling.. this left some unwanted spaces on the forms.

I put the checkboxes that needed the modification on the fly between div tags

Code:

<div ID="test0" style="visibility:visible">
1. for the checkbox1 i added this: style="visibility:visible"
2. I have two versions of the second checkbox.
- one with checked="checked" this is set to hidden by default
- one with out.

Code:

function...
if(...)
{
test0.style.visibility='hidden';
test1.style.visibility='hidden';
test2.style.visibility='visible';
}
if(!...)
{
test0.style.visibility='visible';
test1.style.visibility='visible';
test2.style.visibility='hidden';
}

« BackwardsOnwards »

Show Forum Drop Down Menu