简体   繁体   中英

Javascript Web Crawler Confirm Confirmation box

I am trying to confirm a confirmation box in Javascript for a school project. The confirmation box comes up asking if you want to submit, and I would like to submit programmatically. Here is the HTML for the form:

<form action="https://weekend.lps.wels.net/lpswp/index.php" method="post" id="form_wp_entry" onsubmit="return lpswp_confirm_submission('3,4','Friday,Saturday','Sunday')" style="display: inline;">
                        <table class="em_table" width="100%" style="margin-bottom: 5px;">

                            <tbody><tr>
                                <th align="left" id="lpswp_night_label_title_3">
                                    Friday
                                </th>
                            </tr>
                            <tr>
                                <td>

                                    Location: <input type="radio" name="lpswp_nights[3][location]" id="lpswp_nights_location_dorm_3" value="dorm" checked="checked" onclick="lpswp_toggle_location(3)"> <label for="lpswp_nights_location_dorm_3">Dorm</label> |
                                    <input type="radio" name="lpswp_nights[3][location]" id="lpswp_nights_location_home_3" value="home" onclick="lpswp_toggle_location(3)"> <label for="lpswp_nights_location_home_3">Home</label><br>
                                    <input type="radio" name="lpswp_nights[3][location]" id="lpswp_nights_location_other_3" value="other" onclick="lpswp_toggle_location(3)"> <label for="lpswp_nights_location_other_3" id="lpswp_night_label_text_3">Other</label>: 
                                    <input type="text" size="60" name="lpswp_nights[3][other]" id="lpswp_nights_other_3"><br>
                                    Phone Number (if known): <input type="text" size="20" name="lpswp_nights[3][phone]" id="lpswp_nights_phone_3"> (999-999-9999)
                                </td>
                            </tr>

                            <tr>
                                <th align="left" id="lpswp_night_label_title_4">
                                    Saturday
                                </th>
                            </tr>
                            <tr>
                                <td>
                                    <input type="checkbox" name="lpswp_nights[4][same]" id="lpswp_nights_same_4" value="1" checked="checked" onclick="lpswp_toggle_same(4)"> <label for="lpswp_nights_same_%temp_night%">Same as Friday night.</label><br>
                                    Location: <input disabled="disabled" type="radio" name="lpswp_nights[4][location]" id="lpswp_nights_location_dorm_4" value="dorm" checked="checked" onclick="lpswp_toggle_location(4)"> <label for="lpswp_nights_location_dorm_4">Dorm</label> |
                                    <input disabled="disabled" type="radio" name="lpswp_nights[4][location]" id="lpswp_nights_location_home_4" value="home" onclick="lpswp_toggle_location(4)"> <label for="lpswp_nights_location_home_4">Home</label><br>
                                    <input disabled="disabled" type="radio" name="lpswp_nights[4][location]" id="lpswp_nights_location_other_4" value="other" onclick="lpswp_toggle_location(4)"> <label for="lpswp_nights_location_other_4" id="lpswp_night_label_text_4">Other</label>: 
                                    <input disabled="disabled" type="text" size="60" name="lpswp_nights[4][other]" id="lpswp_nights_other_4"><br>
                                    Phone Number (if known): <input disabled="disabled" type="text" size="20" name="lpswp_nights[4][phone]" id="lpswp_nights_phone_4"> (999-999-9999)
                                </td>
                            </tr>

                            <tr>
                                <th align="left" id="lpswp_final_dinner_label_title">
                                    Sunday Dinner
                                </th>
                            </tr>
                            <tr>
                                <td id="lpswp_final_dinner_label_text" style="border: 0px;">
                                    I WILL be eating in the cafeteria: <input type="radio" name="lpswp_final_dinner" id="lpswp_final_dinner_1" value="1"><br>
                                    I will NOT be eating in the cafeteria: <input type="radio" name="lpswp_final_dinner" id="lpswp_final_dinner_0" value="0"><br>
                                    <input type="hidden" name="lpswp_final_dinner_night" value="5">
                                </td>
                            </tr>
                        </tbody></table>
                    <input type="submit" value="Submit Weekend Plans">
                    <!--input type="reset" value="Cancel" /-->
                    </form>

Here is my current code that does not do anything to the confirmation box:

mWebView.loadUrl("javascript:(function(){" +
                            "document.getElementById('form_wp_entry').setAttribute('onsubmit','return true;');" +
                            ";})()");

Please help me, I am new to javascript... and coding in general.

You're looking for .submit() .
Note that this won't trigger any functionality that's hooked up to the onsubmit of the form:

 function output() { console.log('Submitted'); return false; } // Forcibly submit the form function customSubmit() { document.getElementsByTagName('form')[0].submit(); } 
 <form name="a_form" onsubmit="return output()"> <button type="submit">Submit</button> </form> <br /> <button onclick="customSubmit()">Submit Programmatically</button> 

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM