Monday, August 31, 2009

[jQuery] Re: code not working

My goodness, please do not paste an entire copy of jquery.js in a message to
this group. Your 120KB message was emailed to 20,000 people! All we need is
the version number.

Better yet, don't paste your own code into a message either. Instead, post a
link to a test page that we can load in a browser ourselves. That makes it
*much* easier to look at a problem.

If you do post code in a message, don't post your ASP source. Do a View
Source in your browser to see the generated HTML code that the browser
actually receives. JavaScript and jQuery don't run on your ASP source. They
run on the HTML code that your ASP source generates, as shown by View
Source.

Now since we're here, a few suggestions:

* Update your jQuery 1.3 to the current version, 1.3.2. It's unlikely that
this is related to any problems you're seeing, but there have been a lot of
bug fixes since 1.3.

* Where you have this code:

var parID = $('#txt_num'); //this variable doesn't fill
alert(parID);

What do you mean "doesn't fill"? What does the alert show you? It should
display:

[object Object]

Is that what it shows? What were you expecting it to display? There's no
hint of what you are actually trying to do here.

* You have all sorts of mixed case in your attribute names. ID=, OnChange=,
etc. These should all be lowercase in HTML code. But since I'm looking at
the ASP source, I don't know if it has other requirements.

* Instead of the onchange= attribute for your event handler, it would be
better to use jQuery code. It could be something like this:

<script type ="text/javascript">
$(document).ready( function() {

$('#txt_num').change( function() {
// your code here
});

});
</script>

* When I see code like "doIt(this.form,this,2)" I immediately get the
feeling that there is probably a better way to do it, but since I don't yet
know what "it" is I can't yet make any recommendations.

-Mike

> From: ando
>
> this code is not working and I don't know the reasons for that
> I loaded the file jquery.js that I used
>
> the main code :
>
> <%@ Page Language="VB" AutoEventWireup="false"
> CodeFile="Default.aspx.vb" Inherits="_Default" %>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
> Transitional//EN" "http://
> www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head runat="server">
> <title>Untitled Page</title>
> <script type="text/javascript" src="/js/jQuery.js"></script>
> <script type ="text/javascript" >
> function doIt(form,cntrl,vtype)
> {
> alert(cntrl);
> var ntxt="";
> var parID = $('#txt_num'); //this variable doesn't
> fill
> alert(parID);
>
>
> }
> </script>
>
> </head>
> <body>
>
> <form id="form1" runat="server">
> <table class="style1">
> <tr>
> <td align="right" class="style2">
> <asp:Label ID="Label1" runat="server"
> Text="Numeric"></
> asp:Label>
> </td>
> <td class="style3">
> <asp:TextBox ID="txt_num" runat="server" Width="195px"
> OnChange ="doIt(this.form,this,2)"></asp:TextBox>
> </td>
> <td>
> &nbsp;</td>
> <td>
> &nbsp;</td>
> </tr>
>
> </table>
> </form>
>
> </body>
> </html>

No comments: