Disable dropdown if checkbox ticked problem

Mi MistaT2000 19 Aug, 2008
Hi Folks,

I'm having a problem gettinmg this to work...

I have some javascript but all i seem to be able to do is disable the checkbox 🤣

What I want to do is this..

The user fills out the webform, they then select an option from the dropdown list, 3 options: phone response, email response or letter response, this determines what email address the data will be sent to.. What I want to do is add in a 4th option to say if the checkbox is ticked, disable the dropdown list and send an email to another email address...

Here is the javascript:

function disablefield()
{
	document.ReAssign_A_Call_Form.select.disabled = true;
}


Here is the onsubmit code:

<?php
$emails = array('Email1' => 'email1@email.com', 'Email2' => 'email2@email.com', 'Email3' => 'email3@email.com');
$rows[0]->extraemail = $emails[$_POST['select']];
$sub= "Text: ".$_POST['text']." Response: ".$_POST['select']."Contact ID: ".$_POST['contactid'];
$rows[0]->emailsubject = $sub;
?>
Gr GreyHead 19 Aug, 2008
Hi MistaT2000,

I'm not sure what you are trying to do. There's isn't any 4th email address here - where does that come from?

Perhaps if you post that part of the from html it woudl help.

Bob
Mi MistaT2000 19 Aug, 2008
Hi Bob,

To disable the dropdown list I added the following code:

This to the javascript section:

function disablefield()
{
	document.ReAssign_A_Call_Form.select.disabled = true;
}


This is the checkbox entry in the webform

<input type="checkbox" onclick="disablefield(this.checked)" />


All it seems to do is disable itself once its ticked? the name of my webform is ReAssign_A_Call_Form and the field I want disabled is called 'select'

I'm unsure how to add the checkbox to the onsubmit code so that if its checked it forces the form data to be emailed to a different address and disables the dropdown list so that it doesnt send to one of those addresses too...
Max_admin Max_admin 19 Aug, 2008
well, I would document.getElementById to disable fields, if a field is disabled then it posts nothing, so I would check the post of it and if its unset then use the other option, you dont even need to set a value for the checkbox!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Mi MistaT2000 19 Aug, 2008

well, I would document.getElementById to disable fields, if a field is disabled then it posts nothing, so I would check the post of it and if its unset then use the other option, you dont even need to set a value for the checkbox!



Thanks admin!

I used the following code for the javascript:

window.onload = function() {
document.getElementById('select').disabled =
document.getElementById('checkbox').checked;
}


Then this for my webform:

<
input type="checkbox" name="checkbox" id="checkbox"
onchange="document.getElementById('select').disabled = this.checked;" />


It now works perfectly 😀
Mi MistaT2000 19 Aug, 2008
Just one more question 😶

I was wondering how I assign an email address to the checkbox?

In the onsubmit code I have the following:

<?php
$emails = array('Email1' => 'email1@email.com', 'Email2' => 'email2@email.com', 'Email3' => 'email3@email.com', 'Email4' => 'email4@email.com');
$rows[0]->extraemail = $emails[$_POST['select']];
$sub= "Text: ".$_POST['text']." Response: ".$_POST['select']."Contact ID: ".$_POST['contactid'];
$rows[0]->emailsubject = $sub;
?>


I tried to give the checkbox the value="Email4" but it didnt work.. 😟 Is there any way that in the onsubmit code I can have something that says if checkbox = 'true' then email: [email]'email4@email.com[/email]'??
Max_admin Max_admin 19 Aug, 2008
hi,

I suggested before you do this :

<?php
if($_POST['select']){
$emails = array('Email1' => 'email1@email.com', 'Email2' => 'email2@email.com', 'Email3' => 'email3@email.com', 'Email4' => 'email4@email.com');
$rows[0]->extraemail = $emails[$_POST['select']];
}else{
$rows[0]->extraemail = 'default@something.com';//this is the 4th address
}
?>
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Mi MistaT2000 20 Aug, 2008
Thankyou admin!!!

Your help is, as always, much appreciated!!

Can you delete the other thread I started as I forgot I had already asked the question in this one!!! 😶

Thanks again

MistaT2000
This topic is locked and no more replies can be posted.