skip to Main Content

I have some checkboxes corresponding to some id order:

<input type="checkbox" class="order_id_list" name="order_id_list[]" id="order_id_list" value="{$order.id_order}" />

That i would like to check when I insert the Trackid number:

<input type="text" name="weight_{$order.id_order}" id="weight_{$order.id_order}" size="7" value="{$order.weight}"/>

If it may help I have found the tutorial below but does not work in my case:

<SCRIPT TYPE="text/javascript">
            function recupValeurElement(IdElement)
            {
                if (document.getElementById)
                {
                    return document.getElementById(IdElement);
                }
                else if (document.all)
                {
                    return document.all[IdElement];
                }
            }
            function fctCocherCase(ObjNumber)
            {
                recupValeurElement("Checkbox" + ObjNumber).checked = true;
            }
        </SCRIPT>

<p><input type="text" name="Input1" id="Input1" value="" size="70" onclick="fctCocherCase(1);"></p>
        <input TYPE=CHECKBOX UNCHECKED name="Checkbox1" id="Checkbox1" value="" type="CHECKBOX">

I am really struggling to achieve this unfortunately, any help would be hugely appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    Here is the solution based on Amundria's script and this similar topic:

    Smarty variables in JavaScript

    Here are the modifications to make it work

    <SCRIPT TYPE="text/javascript">
     function check_it(id_order)
    {            
    var checkbox = document.getElementById(id_order);
     if(checkbox)
    checkbox.checked = true; 
    }
    </SCRIPT>
    <td>
    <input type="text" name="weight_{$order.id_order}" id="weight_{$order.id_order}"
     size="7" value="{$order.weight}" onclick="check_it({$order.id_order});" />
                    </td>
    

    Thank you again I very appreciate it


  2. I have simplified the example so you can see how it works without the variables, I don’t know what "{$order.id_order}" is and if it actually works but this example does:

    I gave the textbox a static id (always the same) and used a button to confirm the id you type in the text field instead of OnKeyUp (everytime you type a character) just for the sake of testing.

    It should check the checkbox corresponding to the number you type in the text (1,2 or 3). If you understand how it works then you can easily replace the checkboxes IDs with variables in your loop.

    <SCRIPT TYPE="text/javascript">
    
                    function check_it()
                    {
                      var user_input = document.getElementById("text_box_id").value;
                      var checkbox = document.getElementById("checkbox_" + user_input);
                      if(checkbox)
                        checkbox.checked = true;
                    }
    </SCRIPT>
                    <input type="checkbox" id="checkbox_1" value="cb1">
                    <input type="checkbox" id="checkbox_2" value="cb2">
                    <input type="checkbox" id="checkbox_3" value="cb3">
    
                    <td>
                      <input type="text" id="text_box_id">
                      <button type="button" onclick="check_it()">Confirm ID</button>
                    </td>
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search