перенаправить пользователя на определенную страницу на основе тега выбора с помощью JavaScript? - PullRequest
0 голосов
/ 25 апреля 2018

Я пытаюсь перенаправить пользователя на основе выбора тега HTML с помощью javascript. Мне также нужно установить слово admin для пользователя и пароля?

введите описание изображения здесь

function myFunction() {
	var x = document.getElementById("mySelect");
	var i = x.selectedIndex;

	if (x.options[i].text === "Building 1") {
		window.location.href = "../../realview/Building1/";
	} else if (x.options[i].text === "Building 2") {
		window.location.href = "../../realview/Building2/";
	} else if (x.options[i].text === "Building 3") {
		window.location.href = "../../realview/Building3/";
	} else if (x.options[i].text === "Building 4") {
		window.location.href = "../../realview/Building4/";
	} else if (x.options[i].text === "Building 5") {
		window.location.href = "../../realview/Building5/";
	} else if (x.options[i].text === "Building 6") {
		window.location.href = "../../realview/Building6/";
	} else {
		window.location.href = "../../realview/Building7/";
	}
}
<input id="user" class="input100" type="text" name="email" placeholder="User">
<input class="input100" type="password" name="pass" placeholder="Password">

						 <select id="mySelect" class="login100-form" >
						  <option value="Building 1">Building 1</option>
						  <option value="Building 2">Building 2</option>
						  <option value="Building 3">Building 3</option>
						  <option value="Building 4">Building 4</option>
						  <option value="Building 5">Building 5</option>
						  <option value="Building 6">Building 6</option>
						  <option value="Building 7">Building 7</option>
						</select>

						<div  class="container-login100-form-btn" onclick="myFunction()" >
							<!-- <a href="" target="blank" class="login100-form-btn"  > -->
								<button type="button" class="login100-form-btn"  >
									Login
								</button>								
							</a>
					    </div>

Ответы [ 2 ]

0 голосов
/ 25 апреля 2018
enter code `function myFunction() {
var x = document.getElementById("mySelect");
var i = x.selectedIndex;
var userInput = document.getElementById("userInput").value;
var passInput = document.getElementById("passInput").value;

if (
    x.options[i].text === "Building 1" &&
    userInput === "admin" &&
    passInput === "admin"
) {
    window.location.href = "../../realview/Building1/";
} else if (
    x.options[i].text === "Building 2" &&
    userInput === "admin" &&
    passInput === "admin"
) {
    window.location.href = "../../realview/Building2/";
} else if (
    x.options[i].text === "Building 3" &&
    userInput === "admin" &&
    passInput === "admin"
) {
    window.location.href = "../../realview/Building3/";
} else if (
    x.options[i].text === "Building 4" &&
    userInput === "admin" &&
    passInput === "admin"
) {
    window.location.href = "../../realview/Building4/";
} else if (
    x.options[i].text === "Building 5" &&
    userInput === "admin" &&
    passInput === "admin"
) {
    window.location.href = "../../realview/Building5/";
} else if (
    x.options[i].text === "Building 6" &&
    userInput === "admin" &&
    passInput === "admin"
) {
    window.location.href = "../../realview/Building6/";
} else if (
    x.options[i].text === "Building 7" &&
    userInput === "admin" &&
    passInput === "admin"
) {
    window.location.href = "../../realview/Building7/";
} else {
    alert("There is something error in your login information");
}

} `

0 голосов
/ 25 апреля 2018

function myFunction() {
    	var x = document.getElementById("mySelect");
    	var i = x.selectedIndex;

    	if (x.options[i].text === "Building 1") {
    		window.location.href = "../../realview/Building1/";
    	} else if (x.options[i].text === "Building 2") {
    		window.location.href = "../../realview/Building2/";
    	} else if (x.options[i].text === "Building 3") {
    		window.location.href = "../../realview/Building3/";
    	} else if (x.options[i].text === "Building 4") {
    		window.location.href = "../../realview/Building4/";
    	} else if (x.options[i].text === "Building 5") {
    		window.location.href = "../../realview/Building5/";
    	} else if (x.options[i].text === "Building 6") {
    		window.location.href = "../../realview/Building6/";
    	} else {
    		window.location.href = "../../realview/Building7/";
    	}
    }
function select(){
document.getElementById('user').value="admin";
document.getElementById('password').value="admin";
}
User:<input type="text" name="user" id="user"><br>
Password:<input type="password" name="password" id="password"><br>
    						 <select onchange="select()" id="mySelect" class="login100-form" >
    						  <option value="Building 1">Building 1</option>
    						  <option value="Building 2">Building 2</option>
    						  <option value="Building 3">Building 3</option>
    						  <option value="Building 4">Building 4</option>
    						  <option value="Building 5">Building 5</option>
    						  <option value="Building 6">Building 6</option>
    						  <option value="Building 7">Building 7</option>
    						</select>

    						<div  class="container-login100-form-btn" onclick="myFunction()" >
    							<!-- <a href="" target="blank" class="login100-form-btn"  > -->
    								<button type="button" class="login100-form-btn"  >
    									Login
    								</button>								
    							</a>
    					    </div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...