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:

<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..
P.S one of my firends told me that method=Post in both forms will serve the purpoe. It'll pass variables (from both forms) to a single Perl script. Do you agress?

Dani AI

Generated

wanted to collect a radio choice on page A, another on page B, and have both arrive at one Perl script. That is perfectly possible — but it only happens if you explicitly carry the first value forward. Simply putting method="post" on both forms does not automatically bundle two separate submissions into one request to your Perl code.

Three practical approaches:

  • Client-side carry (no server session). Save the first choice in sessionStorage or append it to the second page URL (GET). The second page reads that stored value and includes it in the final form submission (for example, by adding it to the form data or sending both values via AJAX). See the Web Storage API and URLSearchParams for patterns:
    
    // page1 (store after validation)
    sessionStorage.setItem('firstChoice', selectedValue);

// page2 (read back)
const first = sessionStorage.getItem('firstChoice');

```javascript
// or read from a query string on page2
const params = new URLSearchParams(location.search);
const first = params.get('first_choice');
  • Server-side session. POST the first form to a Perl endpoint that stores the choice in a server session, then render/redirect to the second form. On final submit the server reads the session + posted value and runs the DB query (Perl modules like CGI::Session help with this). This is more secure for sensitive data.

  • Hidden field chaining. As noted, including the first value as a hidden field in the second form is the simplest client-side technique; you can populate that hidden field on page generation (server-side) or with JS on page2.

Two important cautions: remove odd encodings like ENCTYPE="text/plain" unless you intentionally need them — typical HTML forms use the default encoding — and never trust client values alone. Always validate server-side and use parameterized DB queries (DBI) to prevent SQL injection (OWASP guidance). For references see the MDN guides on forms, Web Storage and URLSearchParams, and the Perl CGI::Session/DBI modules.

Recommended Answers

All 2 Replies

Put the data from the first form into a hidden field in the second form.

<input type="hidden" value="data from first form" name="first_data" />

I don't know a lot about Perl, but PHP can definitely do it, and this is not the right forum to ask this question in - Perl. Yes, your friend is correct.

Regards
Arkinder

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.