LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 12:56 PM   #1
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 443

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

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

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, 03:17 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
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, 03:31 PM   #5
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 443

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, 03:38 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
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, 03:46 PM   #7
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 443

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 07:41 AM
PHP form takes forever to submit newuser455 Programming 3 06-09-2005 05:17 AM
javascript: change value of text field and submit codec Programming 3 06-06-2005 09:08 AM
Authentication by Submit Form in Apache??????? ruiseixas Linux - Security 1 11-23-2003 12:02 AM
shell script form submit precioso77 Linux - General 2 05-18-2003 12:50 PM


All times are GMT -5. The time now is 05:33 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration