2

Here is a short form for selecting language for a webpage, There are two languages one is marathi and another is english actually what I want is like: when a user select english language and submit the form english.html page should open and when user select marathi language marathi.html page should open.

<html>
<head>
    <title>Select Language</title>
        <link rel="icon" href="hen.png">

<form>
<center>
    <p id="p1">
    Language:<select>
            <option id="English" >English</option>
            <option id="Marathi" >Marathi</option>
            </select>
    </p>
        <input type="submit" id="button" value="Open" >
</center>
</form>
</html>
Pedro del Sol
  • 2,840
  • 9
  • 39
  • 52

4 Answers4

1

You can use this as a reference, considering english.html and marathi.html as your targeting pages, you can change them accordingly

<html>

<head>
    <title>Select Language</title>
    <link rel="icon" href="hen.png">
    <script>
        $('#button').click(function() {
            var selected = $('#language option:selected');
            window.location.href = selected + ".html"
        })
    </script>
</head>

<body>

    <form>
        <center>
            <p id="p1">
                Language:
                <select id="language">
                    <option id="English">English</option>
                    <option id="Marathi">Marathi</option>
                </select>
            </p>
            <input type="submit" id="button" value="Open">
        </center>
    </form>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</body>

</html>
Praveen Rana
  • 440
  • 7
  • 21
0

I think its obviously, but please do not repeat it at production:

 <input type="submit" id="button" onclick="window.locaton.href='lol/'+$('select').val()+'.html'" value="Open" >
0

Here is easy way;

<select name="forma" onchange="location = this.value;"> <option value="english.html">English</option> <option value="marathi.html">Marathi</option> </select>

Tamang
  • 1
  • 2
0

if you want to create this using simple Javascript then use location.href = "yourPageAddress";

here is the sample code i have written for the same:

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
    <meta charset="utf-8">
    <script type="text/javascript">
        function MyFunction(){
            var getValue = document.getElementById("language");
            //console.log(getValue);
            var getIndexValue = getValue.options[getValue.selectedIndex].value;
            //console.log(getValue.selectedIndex);
            //console.log(getIndexValue);

            if(getValue.selectedIndex == 1){
                //console.log("English")
                location.href = "http://www.google.com";
            }
            else if(getValue.selectedIndex == 2){
                //console.log("Marathi");
                location.href = "http://www.yahoo.com";
            }
            else{
                console.log("Wrong Option Selected.");
            }
        }
    </script>
</head>
<body>
Language:
<select name="language" id="language">
    <option>Select..</option>
    <option value="https://www.google.com" id="english">English</option>
    <option value="https://www.yahoo.com" id="marathi">Marathi</option>
</select>
<br>
<button name="submit" id="submit" onclick="MyFunction()">Submit</button>
</body>
</html>

This is just the one way where you can redirect the user to selected page, there are many different ways also to execute the same operation. You may find some console.log statement marked comment, which was just used for debugging purpose.

shishir
  • 851
  • 3
  • 11
  • 27