LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-01-2005, 11:56 AM   #1
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Rep: Reputation: 30
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
 
Old 06-01-2005, 12:40 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Yes. You just need to execute "document.FORM_NAME.submit()" when you want the data to be submitted.
 
Old 06-01-2005, 02:09 PM   #3
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Original Poster
Rep: Reputation: 30
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
 
Old 06-01-2005, 02:17 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
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">
 
Old 06-01-2005, 02:31 PM   #5
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Original Poster
Rep: Reputation: 30
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
 
Old 06-01-2005, 02:38 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
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>");
 
Old 06-01-2005, 02:46 PM   #7
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Original Poster
Rep: Reputation: 30
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I "submit" an HTML <Form> with Javascript? nickiv Programming 3 06-13-2005 06:41 AM
PHP form takes forever to submit newuser455 Programming 3 06-09-2005 04:17 AM
javascript: change value of text field and submit codec Programming 3 06-06-2005 08:08 AM
Authentication by Submit Form in Apache??????? ruiseixas Linux - Security 1 11-22-2003 11:02 PM
shell script form submit precioso77 Linux - General 2 05-18-2003 11:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration