Click here to Skip to main content
15,921,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Below code is not working:

var valBusType =$('#%=Label2_fromTo.ClientID %>').html();

Thank you all, for your reply. Here I am improving my question so that it can be more understandable and answerable.

I have these controls on my default.aspx page (in .net 3.5)
1:
XML
<asp:DropDownList ID="DdlPickUpPoint" runat="server" CssClass="select" Width="300"></asp:DropDownList>


2:
XML
<asp:TextBox ID="txtSeatNo" runat="server" CssClass="hideBorder" onKeyPress="return false"></asp:TextBox>


3:
XML
<asp:Label ID="lblTotAmt" runat="server"  ></asp:Label>


Now I want to get values of these controls in JScript.js using jquery and then pass it to webservice . Code is below


C#
var valTotValue= =$('#<%=lblTotAmt.ClientID %>').val();
var valSeatNo= =$('#<%=txtSeatNo.ClientID %>').val();
var valPickupPoint =$('#<%=DdlPickUpPoint.ClientID %>').html();
debugger;
$.ajax(
{
 type: "POST",
 url: "WebService_SeatLayout.asmx/GetLayout
 data:"{'strTotValue' : " + valTotValue + ",'strSeatNo': "+ valSeatNo + ",'valSeatNo' : " + valPickupPoint + "}",

contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (msg)
{

alert(msg.d);
if(msg.d==true)
{
 var url = 'CustInfo.aspx';
 window.location.href = url;
 }

           },
           error: function (x, e)
           {
           alert("The call to the server side failed. " + x.responseText);
           }
       }
   );
   return false;
Posted
Updated 27-Oct-12 2:10am
v2
Comments
Sergey Alexandrovich Kryukov 26-Oct-12 15:43pm    
"Not working" is not informative. What did you want to do whith valBusType? Did you check its value under debugger? In this like of code even ever executed? If in doubt, use the debugger or provide debug output into the HTML page being generated in HTTP response.
--SA

It should work, if this is a valid control with valid id. You did not show what you do with valBusTypel and that can also be a problem. The functions returns JavaScript DOM innerHTML property. Please see:
http://api.jquery.com/id-selector/[^],
http://api.jquery.com/html/[^],
http://www.w3schools.com/jsref/prop_html_innerhtml.asp[^].

Please also see my comment to the question.

—SA
 
Share this answer
 
v2
Comments
fjdiewornncalwe 26-Oct-12 16:54pm    
+5. Looks good.
Sergey Alexandrovich Kryukov 26-Oct-12 17:21pm    
Thank you, Marcus.
--SA
NAPorwal(8015059) 27-Oct-12 12:03pm    
@Sergey Alexandrovich : as per your comment I have improved my question, Given all solution dint work in my code,

when i am accessing the Id like this

var pickUpPoint = $('#ctl00_ContentPlaceHolder1_DdlPickUpPoint').find('option:selected').text();

then its working fine can any one plz tell me whts wrong if I am using "ctl00_ContentPlaceHolder1_DdlPickUpPoint" as dropdown id
Try value instead of html:
JavaScript
var valBusType =$('#<%=Label2_fromTo.ClientID %>').value; 

Here:
JavaScript
var valBusType =$('#Label2_fromTo').val();
 
Share this answer
 
v3
Comments
fjdiewornncalwe 26-Oct-12 16:55pm    
I think it should be .val(), not .value as it is jquery.
Sandeep Mewara 26-Oct-12 17:03pm    
:doh: Thanks Marcus.

Updated. Actually, selector too could be simplified.
fjdiewornncalwe 26-Oct-12 17:12pm    
+5. :)
Sergey Alexandrovich Kryukov 26-Oct-12 17:22pm    
Did not get your selector though. '#' requires id...
--SA
Sandeep Mewara 27-Oct-12 1:37am    
Yep. Based on what OP was trying, ID shouls be : Label2_fromTo (Based on this line: Label2_fromTo.ClientID)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900