How to get text value using javascript?

Get the text vlaue on click text.

File name : index.php

<div id="idiv" class="clsdiv">Click on this text:<br/>
Free Web Programming Courses - http://coursesweb.net/</div>
<div id="fff" class="yuyuyu">gfgfgf</div>
<script type="text/javascript"><!--
$(document).ready(function() {
$('div').click(function(){
var idd = $(this).attr('id');
var classdiv = $(this).attr('class');
alert('ID is: '+ idd+ '\n Class: '+ classdiv);
});
});
--></script>

http://coursesweb.net/jquery/get-attribute-id-class-name-title-src-jquery

File name : index.php

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(function(){
$(".lival").on('click','li',function (){
//alert($(this).html())
var li = $(this).html();
alert(li);

$.ajax({
type: "POST",
url: "lidata.php",
data: "size="+li,
success:function(data){
//$("#msg-status").html(data);
alert("Thank you for updating!");
}
});


});
})




</script>


<body>

<input id = "inputid" type = "hidden" />

<div class="lival">
<ul>
<li id="one"> Small</li>
<li id="two"> Medium</li>
<li id="Three">Large</li>
</ul>
</div>









</body>
</html>

File name : lidata.php

<?php
session_start();
$host = "localhost";
$user = "root";
$password = "";
$database = "db_test";

$con = mysqli_connect($host,$user,$password);
mysqli_select_db($con, $database);


$prosize=$_POST['size'];
echo $prosize;

$_SESSION["itemsize"] = $prosize;


?>

How to get list text value using javascript & jquery.

File name : index.php

<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
</head>
<body>

<script type="text/javascript">
$(function(){
$(".Itemsize").on('click','li',function (){
//alert($(this).html())
var lis = $(this).html();
//alert("You have select size : " +lis);

// window.location.href="cart.php?itemsize="+lis;

//document.write("You have select " +lis +"size");

document.getElementById('psize').innerHTML = "You have select size : " +lis;

document.form1.formvar.value = lis;


});

return;
})

</script>

<form name="form1">
<ul class="Itemsize">
<li id="menu-selected">Small</li>
<li id="menu-selected">Medium</li>
<li id="menu-selected">Large</li>
</ul>

<p id="psize"></p>
<input type="text" name="formvar" value="">

</form>
</body>
</html>








How to get text value in javascript?

Get the text vlaue on click text.

File name : index.php

<div id="idiv" class="clsdiv">Click on this text:<br/>
Free Web Programming Courses - http://coursesweb.net/</div>
<div id="fff" class="yuyuyu">gfgfgf</div>
<script type="text/javascript"><!--
$(document).ready(function() {
$('div').click(function(){
var idd = $(this).attr('id');
var classdiv = $(this).attr('class');
alert('ID is: '+ idd+ '\n Class: '+ classdiv);
});
});
--></script>

http://coursesweb.net/jquery/get-attribute-id-class-name-title-src-jquery

File name : index.php

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(function(){
$(".lival").on('click','li',function (){
//alert($(this).html())
var li = $(this).html();
alert(li);

$.ajax({
type: "POST",
url: "lidata.php",
data: "size="+li,
success:function(data){
//$("#msg-status").html(data);
alert("Thank you for updating!");
}
});


});
})




</script>


<body>

<input id = "inputid" type = "hidden" />

<div class="lival">
<ul>
<li id="one"> Small</li>
<li id="two"> Medium</li>
<li id="Three">Large</li>
</ul>
</div>









</body>
</html>

File name : lidata.php

<?php
session_start();
$host = "localhost";
$user = "root";
$password = "";
$database = "db_test";

$con = mysqli_connect($host,$user,$password);
mysqli_select_db($con, $database);


$prosize=$_POST['size'];
echo $prosize;

$_SESSION["itemsize"] = $prosize;


?>

How to get list text value using javascript & jquery.

File name : index.php

<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
</head>
<body>

<script type="text/javascript">
$(function(){
$(".Itemsize").on('click','li',function (){
//alert($(this).html())
var lis = $(this).html();
//alert("You have select size : " +lis);

// window.location.href="cart.php?itemsize="+lis;

//document.write("You have select " +lis +"size");

document.getElementById('psize').innerHTML = "You have select size : " +lis;

document.form1.formvar.value = lis;


});

return;
})

</script>

<form name="form1">
<ul class="Itemsize">
<li id="menu-selected">Small</li>
<li id="menu-selected">Medium</li>
<li id="menu-selected">Large</li>
</ul>

<p id="psize"></p>
<input type="text" name="formvar" value="">

</form>
</body>
</html>







Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here