user895635
user895635

Reputation: 21

html form capture data make url

Could someone explain how I can capture data from two dropdown fields and when the submit button is pressed join these two selection values together to create a URL which is then called.

eg.

DropDown 1: Apple DropDown 2: Orange

When you click submit button it creates a url and loads:

http://www.fruittopick.com/apple-orange.html <-- it concats "apple" & "-" & "orange" & ".html" and then loads that page.

Upvotes: 0

Views: 701

Answers (2)

Different55
Different55

Reputation: 587

if you don't mind a little php:

<?php
$orange = $_POST['orange']; //replace orange with the name of dropdown 1.
$apple = $_POST['apple']; //replace apple with the name of dropdown 2.
$location = "www.example.com/".$orange."-".$apple.".html";
header('Location: '$location);
?>

Set the form's action to a page that contains nothing but the code above. IIRC, it would even pass off any form information.

Upvotes: 1

Manoj
Manoj

Reputation: 487

you can create one javascript function that is to be called when form is submitted, for example see below

function genURL()
{
var orange= document.getElementById('orangeCombo');
var apple= document.getElementById('appleCombo');
var finalURL="www.test.com"; // you can configure as per your need
finalURL= finalURL+orange+apple; // you can configure as per your need
window.location.href=finalURL; // to load generated URL
}

hope it help

Upvotes: 2

Related Questions