Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can't set checkbox to false because my fieldname/idfield contains a PERIOD.????

Posted on 2007-04-04
3
Medium Priority
?
171 Views
Last Modified: 2010-04-16
How can I set this checkbox to false?

I have this function that gets called, the function does some other things, but the one thing it is not doing is setting my checkbox to false so its no longer "checked" visually.  I do not get an error, it just does not work.

function chk(ob,ismaster,requiredCheckBox)      {
            alert(requiredCheckBox);
                requiredCheckBox.checked = false;
}

When I do the alert the value I see is :     required_someUniqueIdField.streetAddress

There is clearly a period in my field names, but that is because they are dynamic and must be this way, but it seems to throw things off.  

So in other words:  requiredCheckBox.checked is really: required_someUniqueIdField.streetAddress.checked = false;  

Is there a way I can keep my current field name and achieve what I want given the fact there is a period in the field name?

Thanks,

-ws
0
Comment
Question by:Westside2004
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
stanscott2 earned 2000 total points
ID: 18852872
Use brackets, rather than dot notation, like this:

<html>
<body>

<form>
     <input type="checkbox" name="thisTest.myName">
</form>

<script type="text/javascript">
   var myCheckBox = "thisTest.myName";
   document.getElementsByTagName("form")[0][myCheckBox].checked = true;
</script>

</body>
</html>

0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 18852979
<script type="text/javascript">
function TestCheckBox (theForm) {
   for (ix=0; ix < theForm.elements.length; ix++) {
       var fld = theForm.elements[ix];
       ///  
       if (fld.name == 'checkbox1.fld1') { fld.checked= false; break; }
   }
   return false;
}
</script>
<form>
<table>
<tr>
<td  colspan="2"><input type="checkbox" name="checkbox1.fld1" checked>Option
</td>
<td>
<input type="button" value="Test " onclick="TestCheckBox(this.form);">
</td>
</tr>
</table>
0
 
LVL 1

Author Comment

by:Westside2004
ID: 18853029
Hi,

I changed the fieldname so it does not have a period in it, but the code still does not work.  Here is the complete code with explanation

I am creating a dynamic form builder where the user can choose a field and decide if this field is required or not.  So if the user checks the box next to the field, that field will appear on a form ultimately.  They also can click a checkbox next to the field and make it that field required or not when the form ultimately renders.

If they choose to make the field required, I automatically select the checkbox next to the field for them.  However, if they deselect the checkbox next to the field, the required checkbox still remains checked and I want to make it UNCHECKED.   It is a bit confusing, but I am hoping this makes sense.

function chk(ob,ismaster,requiredCheckBox)      {
     var isCheck = ob.checked;
     var d=document.getElementsByTagName("input");
     var testAll = true;
   
            for(var i=0;i<d.length;i++) {
   
                  if (!ismaster) {
      // Sub- box was checked
            if (d[i].type && d[i].type=='checkbox') {
              if (d[i].name=='checkAll') {
             var theMaster = d[i];
           }
                               else {
             testAll=(d[i].checked && testAll);  // set testAll to false if any are false
           }
        }
                  }
                  else {
            // Master box was checked
        if(d[i].type && d[i].type=='checkbox' && d[i].name.indexOf((ismaster))!=-1) d[i].checked = isCheck;
      }
   } // close for loop

   if (!ismaster) theMaster.checked=testAll;

      } // close function


The parameter I pass in is called "requiredCheckBox" I want to set this to false if the user unchecks the field.

-ws
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question