简体   繁体   中英

How to display a text in a pop-up screen from an if statement in Javascript?

I would like to display what is in the texbox in the alert message below.

 alert("You have selected: " + cbotherstext);

 <input id="cbotherstext" type="text" /></td>

Thanks so much.

Try this with jquery :

 alert("You have selected: " + $("#cbotherstext").val());

 <input id="cbotherstext" type="text" />

you also need something that call the function eg (with Jquery)

<input id="cbotherstext" type="text" />
<a id="example">Example</a>
<script>
$("#example").click(function(){
    alert("You have selected: " + $("#cbotherstext").val());
});
</script>

Example with JQuery

without Jquery

   <input type="text" id="cbotherstext" >
   <a onclick="alert_val()"> click me</a>
   <script> function alert_val(){
        alert("You have selected: " + document.getElementById('cbotherstext').value);
   }</script>

Without JQuery

This is how to do it:

 alert("You have selected: " + document.getElementById("cbotherstext").value);

 <input id="cbotherstext" type="text" /></td>

Try this

HTML

 <input id="cbotherstext" type="text" />

Script

$("#cbotherstext").keyup(function(){
    alert("You have selected: " + $("#cbotherstext").val());
});

Fiddle

http://jsfiddle.net/EQB68/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM