Jump to content

lcy

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Posts posted by lcy

  1. Solved! Codes used as below

     

    function validateCB(theName){
       var counter=0;
       var cb=document.getElementsByName(theName)
       for (i=0; i<cb.length; i++) {
            if((cb[i].tagName=='INPUT')&&(cb[i].type=='radio')){
              if (cb[i].checked)
                 counter++;
            }
       }
       if (counter==0) {  
       return false;
      }
    return true;
    }
    
    function check(){
    
    
    if (!validateCB('replacement')) {
       		alert("Please fill in all the fields marked with *");
       		return false;
     }
    
             return true;
             }
    

  2. The link provided is not helping.

     

    The number of radio button here is not certain, depending on the result looped from database. I've tried something else using codes below. However, the message box displaying error pop out whenever I do not check the first radio button, which mean that I can just choose the first option.

     

    function check(){
    
    	var replacement = document.getElementById('replacement');
    
    if (!replacement.checked) {
    alert("Please fill in all the fields marked with *");
            replacement.focus();
    return false;
            }
            }
    

     

    This code is working actually. If anyone here know how can I modify this codes to make it works better, your help is appreciated? Thanks.

  3. Hi all.

     

    I have some problems with radio buttons. Hope to get some help here. Thanks in advance.

     

    Here's the html:

    <?php while($row=mysql_fetch_array($result)) { ?>
             <input name="replacement" id="replacement" type="radio" 
                value="<?php echo  $row['date']; echo $row['title']; ?>"
    

     

    I need to validate if none of the radio buttons is checked using javascript. How can I do that? Any help will be appreciated. =)

  4. Hi.

     

    I'm using php and mysql for a system. I have some questions on INSERT query.

     

    When we are using INSERT, in our query....

     

    i. Is it necessary to include each field included in the table we are

    going to insert value with (though some of the field maybe do not

    inserted with value) ?

     

    ii. Have to follow the sequence of the fields in database table?

     

    Thanks in advance.

  5. I've got the solution for the first problem...

     

    function validateCB(theName){

              var counter=0;

              var cb=document.getElementsByName(theName)

              for (i=0; i<cb.length; i++) {

              if((cb.tagName=='INPUT')&&(cb.type=='checkbox')){

              if (cb.checked)

                counter++;

              }

              }

              if (counter==0) { 

            return false;

            }

            return true;

            }

     

            if (!validateCB('company_code[]')) {

      alert("Please select company code");

      return false;

    }

     

    If anyone is having the solution for checking and unchecking all checkboxes, help is much appreciated!!

  6. Thanks for the solutions provided. I tried but they doesn't work. For the remained checking the checked checkbox, i've try another way and it's working.

     

    <?php while($row = mysql_fetch_array($result)){ ?>

            <input type="checkbox" name="company_code[]" value="<?php echo "".$row['company_code'].""; ?>"

            <?php if($company_code!=NULL){foreach ($company_code as $company_code_ticked) 

              {if($company_code_ticked == $row['company_code']){ echo "checked";}}}?>>

            <?php echo $row['company_code']; ?><br>

    <?php  } ?>

     

    Is there any other way to solve my first and second problems? Anyway, appreciate solutions provided.  :)

  7. Hi there. Hope to get some help with checkbox from you guys...thanks in advance.

     

    i have this as my checkboxes:

     

    <?php while($row = mysql_fetch_array($result)) {  >

              <input type="checkbox" name="company_code[]" value="<?php echo "".$row['company_code']."";?>">

              <?php echo $row['company_code']; ?><br><?php  } ?>

     

    Now I'm having three problems here:

    i. to validate if no checkbox is checked

    ii.to apply the check all and uncheck all function

    iii.after the checkboxes are checked and the button submit is checked, the page return to itself. Here i need the checked checkbos to be remained checked.

     

    How can i do all these with the checkbox i'm having. Appreciate any help given. Thanks again. :)

  8. Hi! Having some problems regarding radio buttons..hope to get some help here.

    Thanks in advance.  :)

     

    Here's the code:

     

    $query = "SELECT * from replacement_leave

                WHERE a=1 && b=2 && c=3'";

    $result = mysql_query($query) or die ("couldn't execute query");

     

    <tr>

    while($row=mysql_fetch_array) { ?>

     

    <td><input name="replacement" type="radio" value="<?php echo $row['date']; echo $row['title']; ?>" checked></td>

    <td><?php echo $row['title']; ?></td>

    <td><?php echo date('d-m-Y',strtotime($row['date']));?></td>

    <td><?php echo $row['entitlement']; ?></td>

    <td><?php echo $left; ?></td>

    <td><?php echo $row['validity']; ?></td>

    </tr><? } ?>

     

     

    First, i need the radio button to be checked initially for the first value of the radio button. However, what i get is, the button is checked at the last item appears in the list of radio button.

     

    Second, after users make their choice and submit the form, they are able to return to this page. When they return to this page, the radio button is needed to be checked on the users' previously chosen button. But i don't know how to make this.

     

    Thanks again for helping. ;)

  9. This is my table: (table.php)

     

     

    <? while ($row9 = mysql_fetch_array($result9)) {  ?>

     

     

    <td width="7%" bgcolor="#FFFFCC">Company</td>

    <td width="18%" bgcolor="#FFFFCC">NRIC</strong></td>

    <td width="44%"  bgcolor="#FFFFCC">Name</td>

    <td width="11%"  bgcolor="#FFFFCC">Validity</td>

    <td width="15%"  bgcolor="#FFFFCC">Update Validity</td>

     

    <td><? echo "".$row12['company_code']."";?></td>

    <td><? echo "".$row9['NRIC']."-".$row9['NRIC1']."-".$row9['NRIC2']."";?></td>

    <td><? echo "".$row12['name']."";?></div></td>

    <td><input type="text" name="validity_new" value="<?php if ($row9['validity'] != NULL){echo   

          $row9['validity'];}?>" size="1" maxlength="3"></td>

    <td><div align="center"><input type="image" name="update_validity" value="<? echo 

          "".$row9['NRIC']."-".$row9['NRIC1']."-".$row9['NRIC2']."";?>" src="Pictures/4.png" alt="submit button"

          width="20" height="20"/></div></td>

     

     

     

    Once the "Update Validity" button is pushed, the data is passed to "update.php".

     

    $validity_new = $_POST['validity_new'];

     

    In "update.php", the value of updated validity for only the selected row cant be retrieved. Only if value for validity for all the row in the table are changed to a same value, the updated value can be retrieved in the update.php.

     

     

    I just want to update validity for the row selected. How can i do this? Thanks a lot.

  10. Gd morning!

     

    I have a table diplaying a list of data which is called from the database (based on selection made earlier).

    I use "while($row=my_sql_fetch_array($result)" to call all data for that table.

     

    Now, i need to update one of the data field of the table for the chosen row only.

    I use text field to display the data to make it editable.

    Then i create a button for each row to pass all needed data and the updated data to the following page where update takes place.

     

    However, the ediited value only for that chosen row cant be grabbed and be passed to the next page.

     

    How should i solve this?

     

    Thanks in advance.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.