SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript/HTML passing info from one form to another

    Hi..I am a newbie in JavaScript.I have two forms (in two different webpages) all with radio buttons. A user cannot select more than one option from each form. My plan is to pass the user input from both the forms to a perl script which would then query a MySQL db for the output and display it.
    Now my question is, is it possible to pass the data from first form to second using GET/POST method in Radio form? Will it be possible to pass both data from first and second form into the Perl code?
    My first form page named as index.html page and the second one is named as party_names.html.
    The form code I used in the first index.html page is:
    Code:
    <form action="party_names.html" method=post name="Candidate_name" ENCTYPE= text/plain onsubmit="return form_validation(this)">
    I have a JavaScript function to validate form data so that it can check whether a radio button is selected after clicking next button to go to next html form page. Please suggest.
    Many thanks in advance..

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by pratul View Post
    I have a JavaScript function to validate form data so that it can check whether a radio button is selected after clicking next button to go to next html form page.
    You can pass from the first to the second using the GET protocol so that JavaScript can retrieve the values and load them in to hidden form fields, but then you are guaranteeing that the form will only with for people with scripting enabled.

    The better way is to submit the form to server-side code, so that you can retrieve the submitted form data (as either POST or GET) and put the values in hidden form fields or in session data for the next page.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi thanks for your reply. Basically I will supply the variables in Perl at the end to interact with MySQL DB with my variables. My second form will have a code like this
    Code:
    <FORM action="myscript.pl" method=POST
    ..But for that I want to make sure that user selected variables (from two different forms) are going to pass to the script. So you're saying that the GET or POST in both forms will serve the purpose. Am I rite?
    So the code parts I given in my earlier post and in this post are correct?
    Thanks again for your reply..

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by pratul View Post
    I want to make sure that user selected variables (from two different forms) are going to pass to the script. So you're saying that the GET or POST in both forms will serve the purpose. Am I rite?
    First you need to get the submitted form values from the first page, to show up in the second page. If server-side code will be receiving the submitted form from the second page, then using POST will work well.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No.. server side code (in my case Perl script) should work with the values from both forms. Not only the second one. In this case, POST will work?

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by pratul View Post
    No.. server side code (in my case Perl script) should work with the values from both forms. Not only the second one. In this case, POST will work?
    If the first page is submitted to a Perl script, and the Perl script is used to create the second page, then POST is good to be used.

    Will a Perl script be used to retrieve the first page's submitted data?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The form value from the first page does not show up in second one. Both are different forms and used radio buttons in both forms. But I need the variables from both forms in my Perl script to work.
    Thanks

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by pratul View Post
    The form value from the first page does not show up in second one. Both are different forms and used radio buttons in both forms. But I need the variables from both forms in my Perl script to work.
    Thanks
    Let's work backwards then. If you require the Perl script to receive the values from both forms, that must mean that the second form has to contain the values from the first form. Preferably as hidden values in the second form, right?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The first page has a next button. So after selecting a Radio button, user clicks Next butto and goes to the next Form and selects a Radio button from a different form. Now I want the selections from both forms to be passed in Perl.
    So my first page contains this code:
    <form action="party_names.html" method=post name="Candidate_name" ENCTYPE= text/plain onsubmit="return form_validation(this)">
    and it takes me to the secnd page and the second page has a submit button to go to Perl script..
    Thanks

  10. #10
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that must mean that the second form has to contain the values from the first form. Preferably as hidden values in the second form, right?
    Yes.. right

  11. #11
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by pratul View Post
    Yes.. right
    Okay, good. So you need a way to modify the second form so that the first-form values are added to it.

    With JavaScript that can only be done as a GET submission, and it is guaranteed to fail when client-side scripting is not available.

    With server-side code, you can use either GET or POST submissions, and it's guaranteed to work regardless of whether clisnet-side scripting is supported or not.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  12. #12
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should I send you all the codes?

  13. #13
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by pratul View Post
    Yes.. right
    Okay, good. So you need a way to modify the second form so that the first-form values are added to it.

    With JavaScript that can only be done as a GET submission, and it is guaranteed to fail when client-side scripting is not available.
    With server-side code, you can use either GET or POST submissions, and it's guaranteed to work regardless of whether client-side scripting is supported or not.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  14. #14
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by pratul View Post
    Should I send you all the codes?
    No. I don't do any work for you. Instead I will help you to find the answers for yourself.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  15. #15
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I wanted to send you only the codes of the Form part..
    but I think I am getting it now...I should work with POST method then...
    Thanks a lot for your help..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •