I am generating text boxes and check boxes as I move through a recordset.

       echo "<td>".$i."</td><td><input name=UserName".$i." type=text onKeyPress=return noenter() size=20
         value=".$row['UserName']."></td>";
       echo "<td><input name=Password".$i." type=text onKeyPress=return noenter() size=20
         value=".$row['Password']."></td>";
       echo "<td><input name=InputDate".$i." type=text onKeyPress=return noenter() size=20
         value=".$row['InputDate']."></td>";
       echo "<td><Input name=deleteBox".$i." type=checkbox value=Delete>Delete</td>";
       echo "<td><Input name=editBox".$i." type=checkbox value=Edit>Edit</td>";

This should be super simple, but I don't get it yet. I need to make the edit and delete checkboxes fire some code (preferably "do you want to edit / delete...")

I've not had any luck to this point with it.

Thanks
Jay

    U should try posting on ClientSide Technologies, this is javascript problem; any way u should check for checkbox (checked) or validate input text field on "onsubmit" event, or if the user click on a checkbox, u should have onclick event (onclick="return confirm('Are u sure?');"), any way your question is so general (u should be more specific on what u want) and the best section of this forum for your question is the one I told u above ...

      Make sure you quote all attribute values in HTML correctly.

      A HTML checkbox should fire onclick when it is clicked (or activated by some other method, e.g. keyboard or clicked on its label), and will fire onchange when it loses focus following a change of its value.

      Mark

        I've looked through the Client Side Technologies, but didn't find anything that has helped me so far, and I'm getting pretty stumped on this one. Here's what I'm doing so far:

           while ($row = mysql_fetch_assoc($AppRS)) 
           { 
               echo "<td>".$i."</td><td><input name=UserName".$i." type=text onKeyPress=return noenter() size=20
                 value=".$row['UserName']."></td>";
               echo "<td><input name=Password".$i." type=text onKeyPress=return noenter() size=20
                 value=".$row['Password']."></td>";
               echo "<td><input name=InputDate".$i." type=text onKeyPress=return noenter() size=20
                 value=".$row['InputDate']."></td>";
               echo "<td><Input name=deleteBox".$i." type=checkbox onclick=return DelFunction(UserName$i,Password$i) value=Delete>Delete</td>";
               echo "<td><Input name=editBox".$i." type=checkbox value=Edit>Edit</td>";
        
        echo "</tr>\n"; 
        $i=$i+1;
           } 
        

        I'm trying to call this function:

        function DelFunction($User,$Pass)
        {
          mysql_select_db($database_app, $app);
          $query_App = "DELETE * FROM users where UserName=".$User." and Password=".$Pass." ORDER BY UserName";
          $AppRS = mysql_query($query_App, $app) or die(mysql_error());
          if ($AppRS=True)
          {
            $Reloadable ="DisplayUsers.php";
            header(sprintf("Location: %s", $insertGoTo));
          }
          else
          {
            $Reloadable ="DisplayUsers.php";
            header(sprintf("Location: %s", $insertGoTo));
          }
        }
        

        I can't see that it is even trying to do anything when I click one of my delete checkboxes...

        Thanks

          Have another look at MarkR's advice...

            You cannot call a server-side function from a client-side call. At least not directly. You need to use either AJAX or just submit the form and depending on POST (or GET) values, determine the server-side code to call (which you need to do.) In fact, what you want to do is pretty simple. On your checkbox onclick events just submit the form. Then, in the form handler, look for the checkbox names under the $POST array using the isset() function. Of course you'll need to loop through the entire $POST array to match the numbers represented by $i (I'll leave that to another thread.)

              Moved to ClientSide Technologies forum, as your current problem and the likely solution will both deal with client-side scripting.

              As Rodney suggested, Mark has already told you part of your problem:

              MarkR wrote:

              Make sure you quote all attribute values in HTML correctly.

              In your HTML INPUT entities, you don't quote any of the values.

              Though this will fix your current issue, it will not achieve the desired result. As is mentioned above, you can't directly call a function written in a server-side script from the client.

                I wish I was understanding better...

                I'm using echo " " to make these lines, so I can't quote the line like what I've seen in some other examples without getting parse errors.

                Do I need to do something like this?
                onclick=<script text/javascript>some scripty code here...</script>

                  j_w_Bruce wrote:

                  I wish I was understanding better...

                  I'm using echo " " to make these lines, so I can't quote the line like what I've seen in some other examples without getting parse errors.

                  Do I need to do something like this?
                  onclick=<script text/javascript>some scripty code here...</script>

                  ummmm...you might wanna start learning the fundamentals of HTML and clientside scripting before jumping into the serverside stuff. Just a thought.

                    j_w_Bruce wrote:

                    I'm using echo " " to make these lines, so I can't quote the line like what I've seen in some other examples without getting parse errors.

                    Why not?

                    echo "Here are some \"quotes\"!"; // Here are some "quotes"!

                    Besides, HTML also accepts single quotes as string delimiters.

                      I've tried the single quotes and the double quotes:

                          echo "<td><Input name=\"deleteBox".$i."\" onclick=\"return CheckButtons($i)\" type=\"checkbox\" value=\"Delete\">Delete</td>";         

                      My code on the finished page is looking like this:
                      <td>1</td><td><input name=UserName1 type=text onKeyPress=return noenter() size=20
                      value=12345></td><td><input name=Password1 type=text onKeyPress=return noenter() size=20
                      value=2345></td><td><input name=InputDate1 type=text onKeyPress=return noenter() size=20
                      <td><Input name="deleteBox1" onclick="return CheckButtons(1)" type="checkbox" value="Delete">Delete</td>

                      But when I click the button, this is what I'm getting:
                      error 0, object required

                      I've tried calling a php function, but the general consensus was that I needed to be calling java script so here is what I have lower in the page...

                      <script type='text/javascript' language='JavaScript'>
                      function CheckButtons()
                      {
                      alert "Warning, you've clicked a box";
                      }
                      </script>

                      Thanks for all the help so far.

                        First of all, you need to surround your HTML values in quotes, such as the onKeyPress=return noenter() part SHOULD be onKeyPress="return noenter()".

                        And yes, PHP is a server-side scripting language, so you can't call PHP functions from the client (the rendered page). In JavaScript, alert isn't a language construct like [man]echo[/man] in PHP - it's a function. So, you need to use it like so:

                        alert("Warning, you've clicked a box");

                        Also, just for some HTML cleanup, the "language" attribute of the SCRIPT tag is not only superfluous, but not even a valid attribute by W3C standards; I would remove it and stick with type='text/javascript'.

                          Thanks for the replies. I finally started getting the code down to the Script.

                          I've gotten the check box fixed like so:
                          echo "<td><Input name=\"deleteBox".$i."\" onclick=\"return CheckButtons($i)\" type=\"checkbox\" value=\"Delete\">Delete</td>";

                          Then I have my script doing this:

                          <script type='text/javascript'>
                          <!--
                          function CheckButtons(SelectedItems)
                          {
                          var Selection=SelectedItems;
                          var YesNo=confirm ("You are working with Item Number " + Selection + " Continue?");
                          if (YesNo)
                          {
                          var UserBox=document.frmForm.UserName+Selection.value;
                          var PassBox=document.frmForm.Password+Selection.value;
                          alert (UserBox + " " + PassBox);
                          }
                          }
                          -->
                          </script>

                          I'm getting my Alert that says "you are working with 10". That is working.

                          But I'm having a problem with this line now.

                             var UserBox=document.frmForm.UserName+Selection.value; 
                             var PassBox=document.frmForm.Password+Selection.value;
                             alert (UserBox + " " + PassBox);

                          My second Alert is giving me this "NaN Nan"

                          Each answer seem to lead to more questions... But I do appreciate the help.
                          Thanks

                            Erm, the "Selection" variable contains a number, not a reference to an HTML entity. So... why are you trying to do "Selection.value" ?

                              Well, I've numbered my boxes as I created them ie. UserName1, UserName2, UserName3..., UserName34. Selection tells me what row number was clicked on. So now I'm trying to put it back together to pull the text that was in UserName(x) and Password(x)

                              Maybe there is a way better way to do it.

                              Thanks

                                Ahh, I see. So technically, you want to use variable variable names. Sort of like doing ${'Username' . $i} in PHP. In that case, I'd say do something like this:

                                eval('var UserBox=document.frmForm.UserName'+Selection+'.value');
                                eval('var PassBox=document.frmForm.Password'+Selection+'.value');

                                  Excellent, exactly what I was looking for. Thanks!!

                                    Write a Reply...