查询有关警报消息

查询有关警报消息

本文介绍了查询有关警报消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi everyone,

I created a login form in html. when i entered data in the form it should be display all details in alert message for that i wrote and code like this.
<pre><!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
  var id1=document.getElementById("firstname").value;
  var id2=document.getElementById("lastname").value;
  var id3=document.querySelector('input[name="gender"]:checked').value;
  var id4=document.getElementById("dob").value;
  var id5=document.getElementById("email").value;
  var id6=document.querySelector('input[name="nat"]:checked').value;
  var id7=document.getElementById("city").value;
  
    alert(id1+id2+id3+id4+id5+id6+id7);
    
  
}
</script>
</head>
<body>
<form action="/action_page.php">
<h2>Login Form</h2>
<fieldset>
<legend>Personal Information:</legend>
First name:<br/>
<input type="text" name="firstname" id="firstname"><br/><br/>

Last name:<br/>
<input type="text" name="lastname" id="lastname"><br/><br/>

Gender:<br/>
<div id="rates">
<input type="radio" name="gender" value="male"> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</div>
<br/>

Birthday:
<input type="date" name="bday" id="dob">
<br/><br/>

E-mail:
<input type="email" name="email" size="40" id="email">
<br/><br/>

City:
<select name="City" id="city">
<option value="Hyderabad">Hyderabad</option>
<option value="Chennai">Chennai</option>
<option value="Bangalore">Bangalore</option>
<option value="Noida">Noida</option>
</select>
<br/><br/>

Nationality:<br>
<div id="nat">
<input type="checkbox" name="nat" value="Indian" id="ind">Indian
<input type="checkbox" name="nat" value="Other" id="oth">Other
<br/><br/>
<button onclick="myFunction()">Try it</button>
</div>
</form>
</fieldset>
</body>
</html>







but i would like do in another way when i entered firstname and lastname it should display those values only in alert message or if i entered firstname,lastname,dob those values only it should display. so which value i entered in form it should display those values in one alert message.





我尝试过的方法:





What I have tried:

<pre>but i would like do in another way when i entered firstname and lastname it should display those values only in alert message or if i entered firstname,lastname,dob those values only it should display. so which value i entered in form it should display those values in one alert message.

推荐答案

try this one

function myFunction() {
  var id1=document.getElementById("firstname").value;
  var id2=document.getElementById("lastname").value;
  var id3=document.querySelector('input[name="gender"]:checked')!=null?document.querySelector('input[name="gender"]:checked').value:'';
  var id4=document.getElementById("dob").value;
  var id5=document.getElementById("email").value;
  var id6=document.querySelector('input[name="nat"]:checked')!=null?document.querySelector('input[name="nat"]:checked').value:'';
  var id7=document.getElementById("city").value;
  
    alert(id1+id2+id3+id4+id5+id6+id7);
    
  
}
Hope Its help you.


这篇关于查询有关警报消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 20:10