LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   submit a form with javascript (https://www.linuxquestions.org/questions/programming-9/submit-a-form-with-javascript-329225/)

djgerbavore 06-01-2005 11:56 AM

submit a form with javascript
 
hello,

i have a question about javascript. I want a user to click on a button which brings up a new window. That part is easy, i know how to implement that, but my trouble is in the new window i want to be able to make a form and be able to submit that form to either a database or another link. is this possible with javascript?????


let me know it this isn't clear enough

thanks,

djgerbavor3

david_ross 06-01-2005 12:40 PM

Yes. You just need to execute "document.FORM_NAME.submit()" when you want the data to be submitted.

djgerbavore 06-01-2005 02:09 PM

i'm alittle confuse.

how would i do that.
i have a funtion that pops ups a new window were the form is going to be.

Code:

function form_window() {
  newWin = window.open("", "toolbar=yes, width=650, height=600, resizable=yes");
  newWin.document.write( /*put the form code here*/);
  //add a submit button
  var submitButton = newWin.document.createElement("input");
  submitButton.setAttribute("type", "submit");
  submitButton.setAttribute("value", "Submit");
  newWin.document.body.appendChild(submitButton);
}

how would i include document.FORM_NAME.submit(), so when i click on the submit it will take me to a new page?????


thanks,
djgerbavor3

david_ross 06-01-2005 02:17 PM

If your form actually has a submit button then you don't need to use javascript to submit it. Just set the action variable in the form to be the page you are taken to - ie:
<form action="myscript.php">

djgerbavore 06-01-2005 02:31 PM

okay here is what i have:

Code:

function form_window() {
  newWin = window.open("", "toolbar=yes, width=650, height=600, resizable=yes");
  newWin.document.write("<form action=\"foo.php\" method='POST'>");
  newWin.document.write( /*put the form code here*/);
  //add a submit button
  var submitButton = newWin.document.createElement("input");
  submitButton.setAttribute("type", "submit");
  submitButton.setAttribute("value", "Submit");
  newWin.document.body.appendChild(submitButton);
  newWin.document.write("</form>");
}

when i click on the submit button nothing happens, and i checked mozilla's javascript console and it doesn't show any errors??? Am i doing something wrong??

thanks for you time,

djgerbavor3

david_ross 06-01-2005 02:38 PM

My only guess is that the submit button is not being written within the form - try using:
newWin.document.write("<input type=\"submit\" value=\"Submit Form\">");
newWin.document.write("</form>");

djgerbavore 06-01-2005 02:46 PM

hahah that worked!!!!!!!!!!! i can't believe i didn't know that :) oh well you learn something new every day. Thanks for you help.

djgerbavor3


All times are GMT -5. The time now is 02:51 AM.