Good day. There are many inputs that are generated by the system. I need to display the value of inputs separately in the body of the site.

the person clicks on the rocker and knowledge changes

input code

since the system generates an automatic (plugin), then I attached to the name and pulled the value into a div block, but it does not change dynamically when a person clicks on the rocker.

<script type="text/javascript"> jQuery(document).ready(function($) { var value_input = $("input[name*='product-options[1271][58]']").val(); $("#for_my_script").append("<p>" + value_input + "</p>") }); </script> 

I will be grateful for the help. thank.

    2 answers 2

    In this case, the values ​​are written at the document.ready () event, that is, when the DOM is loaded.

    In order for the values ​​in the "for_my_script" div to change automatically, you need to hang the event on the rocker buttons.

    You can create a function and call it every time you press the rocker.

     function RefreshDiv(){ var value_input = $("input[name*='product-options[1271][58]']").val(); $("#for_my_script").html("<p>" + value_input + "</p>") } 

    You can also call it (if needed) with document.ready ():

     jQuery(document).ready(function{ RefreshDiv(); }); 
    • Sorry for the stupidity, but I'm no in jq. hence the question - how to tie to the rocker? and take into account that there are 2 for one input, but there are 20 pieces of inputTaras Bezdushnuy
    • Alternatively, simply attach to the "ui-spinner-button" button class: $('.ui-spinner-button').click(function(){ RefreshDiv(); }); - Kernel Panic

    Use the change event instead of jQuery (document) .ready (function ($))

     $("input[name*='product-options[1271][58]']").change(function() { var value_input = $("input[name*='product-options[1271][58]']").val(); $("#for_my_script").append("<p>" + value_input + "</p>") } 
    • tried it. replaced your code with yours. no changes. in my boot, it pulls out the value (0 by default) does not change when changing. after the change - nothing happens and there is no value. even by default which. Sori for stupidity, I'm bad in js - Taras Bezdushnuy
    • This code must be inserted after the HTML code, or inside your jQuery (document) .ready (function {...} - Jeid