Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
78 views
in Technique[技术] by (71.8m points)

javascript - How to change the value for the data we set of an input when we leave the page?

I don't get how to change the value of an input field in a php foreach, The value display is contain in a string array, I want it to change when the user change page not whenever he changes the value of the field. Any idea how to do that? any help will be welcome! here is the code

foreach ($listeValeur as $value) {
                $i ++;
                ?> 
                <form action="" method="post">
                    <tr>
                        <td>
                            <input onChange="this.form.submit();" name="leChamp" type="text" class="form-control" id="usr" value="<?php echo $value;?>">
                        </td>
                        <td style="text-align: center; vertical-align: middle;"> 
                            <button class="buttonNoStyle" type="submit" name="supprimerLeChoix"><i class="pointer colorIconDeleteLight iconSize fas fa-times" title="Supprimer le choix"></i></button>
                            <button class="buttonNoStyle" type="submit" name="supprimerTout"><i class="pointer colorIconDeleteStrong iconSize secondIconPadding fas fa-trash-alt" title="Tout supprimer"></i></button>
                        </td>
                    </tr>
                </form>
            <?php
            }
question from:https://stackoverflow.com/questions/65951450/how-to-change-the-value-for-the-data-we-set-of-an-input-when-we-leave-the-page

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you don't want the the form to be submitted as soon as the user types in the box, then you should remove the "onChange" event from the textbox.

Then the user will need to press the submit button before the data will be sent to the server.

i.e. remove this:

onChange="this.form.submit();"

If you weren't sure what this code was doing, please read https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...