Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
80 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...