Form script Question

M

Marc Dimmick

I am trying to check that a check box has been check and if it has then
display the label in the email I generate.

I am creating a function chkboxvalidate (chk,label) I am just not sure how
to pull the value in the check box and the label given to the check box..

I have the following:

function chkboxvalidate (chk,label);
{
var sSystem = document.getElementByID("chk");
if (chk.checked)
var sSystem = label.innerText;
return sSystem;
}

Just not really understanding how to get the function to work. I have
created email buttons which generate an email base on the content of the
form and based on the boxes selected to try and display their lables. Anyone
got some pointers??
 
A

Andy Henderson

Assuming you are using something like:
<label id="label1"><input type="checkbox" name="xyz" id="chk1" />This is the
text to return</label>

And your call is:

chkboxvalidate("chk1", "label1");

Then the (untested) code would be something like:

function chkboxvalidate (chk,label);
{
var chk = document.getElementByID("chk");
if (chk.checked) {
return document.getElementByID("label").innerText;
}
return '';
}

Note that you need to get the label element so you can reference it's text
(I'm not sure if you'll also get the <input> tag mixed in with it, though).
Also, return stops execution of the function and returns the value. So the
return ''; statement will execute only if the box is unchecked.

HTH,

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top