Just as the title says, I need help with javascript code that will open a webpage and fill out the form then submit the information.
Here is what I have currently:
var firstName = 'Billy';
var lastName = 'Bob';
var loginWindow = window.open('my website', 'loginWindow');
loginWindow.document.getElementById('fname').value=firstName;
loginWindow.document.getElementById('lname').value=lastName;
loginWindow.document.form.submit();
(I found it on another post).. but it does not work for me.
There may be XSS (Cross-Site Scripting) restrictions on this. But, there is a solution.
Browse the source code of the form you want, find the
formtag’sactionattribute (<form action="THIS STUFF HERE">...</form>), and then do one of the following in the scripting for your page:Use it as the
actionof a newformand use the DOM to addhidden inputelements with thenames andvalues of the data you want to submit, then use.click()on thesubmitbutton to the newform.Browse in some way to the action URL, but append
?name1=value1&name2=value2&name3=value3..., wherename1andvalue1, etc., are the names and values of the form fields you want to submit. If there is already something similar to this at the end of theactionURL, just add on new&name=valuepairs instead of appending a new question mark. (This could be done using aniframewith CSSdisplay: none;.Hope this helps!!