This topic is locked

Checkbox to activate textbox

2/10/2009 6:08:33 PM
ASPRunnerPro General questions
A
agruspe author

I have a field as a checkbox and textbox in a form. The text box would be greyed out and no info can be entered UNTIL the checkbox is checked. Once the checkbox is checked the textbox becomes active and information then can be entered.
Can you please provide code to do this.

Sergey Kornilov admin 2/12/2009

Arnel,
check the following link for inspiration:

http://www.webdeveloper.com/forum/archive/...hp/t-32879.html

A
agruspe author 2/12/2009

Hi Sergey,
Thanks for the information. Can you please tell me where can I modify the code?
I do not see this in the Visual Editor. When in HTML mode, all I see is {checkbox_editcontrol} for the checkbox and {textbox_editcontrol} for the textbox.
Thanks in advance.
Regards,

Arnel

J
Jane 2/13/2009

Hi,
you can add your onclick function at the end of HTML code.

Here is a sample:

http://www.asprunner.com/forums/index.php?showtopic=6503

A
agruspe author 2/16/2009

Hi Jane,
I still cannot make it work. Below is the code that I am using:

<script>

document.forms.editform.value_isduration.onchange=function()

{

if(this.options[this.selectedIndex].checked)

document.forms.editform.value_enddate.disabled=false;

document.forms.editform.value_endtime.disabled=false;

else

{

document.forms.editform.value_enddate.disabled=true;

document.forms.editform.value_endtime.disabled=true;

}

}

</SCRIPT>



Take note that I have to insert the above code before the

{END body}


Please confirm if I need to change the "editform" name to the name of the add/edit page.

J
Jane 2/17/2009

Hi,
please see my change inBold:

<script>

document.forms.editform.value_isduration.onchange=function()

{

if(document.forms.editform.value_isduration.checked)

{

document.forms.editform.value_enddate.disabled=false;

document.forms.editform.value_endtime.disabled=false;

}

else

{

document.forms.editform.value_enddate.disabled=true;

document.forms.editform.value_endtime.disabled=true;

}

}

</SCRIPT>

A
agruspe author 2/17/2009

Hi Jane,
Great! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=37907&image=1&table=forumreplies' class='bbc_emoticon' alt='B)' /> Super! It is now working. Jane for President!!! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=37907&image=2&table=forumreplies' class='bbc_emoticon' alt=':lol:' />
NOTE TO OTHER USERS:

This works only if the date field (or any field) as long as the input format is simple text box. It does not work if the input format is dropdown boxes with date picker.
Below is the complete code. The first script is to check the initial state of the checkbox while the second script is to check if the checkbox state has been changed.

<script>

if(document.forms.editform.value_isduration.checked)

{

document.forms.editform.value_enddate.disabled=false;

document.forms.editform.value_endtime.disabled=false;

}

else

{

document.forms.editform.value_enddate.disabled=true;

document.forms.editform.value_endtime.disabled=true;

}

</SCRIPT>
<script>

document.forms.editform.value_isduration.onchange=function()

{

if(document.forms.editform.value_isduration.checked)

{

document.forms.editform.value_enddate.disabled=false;

document.forms.editform.value_endtime.disabled=false;

}

else

{

document.forms.editform.value_enddate.disabled=true;

document.forms.editform.value_endtime.disabled=true;

}

}

</SCRIPT>

A
agruspe author 2/17/2009

Hi Jane,
I tried using dayvalue_enddate, monthvalue_endate and yearvalue_endate but it does not work <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=37916&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' /> . Please advise the field names for the dropdown box with date picker..
Thank you very much for the support...

J
Jane 2/19/2009

Hi,
just open this page in browser, right click on the page, select View page source and check correct names for these dropdowns.