Re: [jQuery] noob q - using $().html

2007-01-04 Thread Klaus Hartl
Doug Tabacco schrieb:
> True, but if it's not meant to be submittable, you could always just 
> remove the form tags as well.

I always think of graceful degradation when building scripts/pages. With 
JavaScript off any form is submittable, no matter if it is meant to be 
or not.

 From the initial post it wasn't clear, that there's no need for a form 
at all, that's why I suggested a complete solution and not something 
that seems to be more like an insufficient workaround.


-- Klaus

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-04 Thread Daniel McBrearty
OK, I've fixed it. I also had a table which was used to align elements
which I had omitted for clarity. I looked up prev(), and saw that it
looks for the "unique previous element" ... removed the table and all
is OK.

My code us now this:

(in myapp.js )

$(document).ready(function() {
  $('#find_member_button').click(function() {
var username = $(this).prev().val();
$("#member_info").html(username);
return false;
  });

});

(in the html )






which is WAY cleaner. Thanks. I learned a few things :-)


On 1/4/07, Daniel McBrearty <[EMAIL PROTECTED]> wrote:
> and yes, I've gone over to using a button type, and will likely cut
> out the form tags too. thanks for that suggestion Doug.
>
> --
> Daniel McBrearty
> email : danielmcbrearty at gmail.com
> www.engoi.com : the multi - language vocab trainer
> BTW : 0873928131
>


-- 
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-04 Thread Daniel McBrearty
and yes, I've gone over to using a button type, and will likely cut
out the form tags too. thanks for that suggestion Doug.

-- 
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-04 Thread Daniel McBrearty
On 1/4/07, Karl Swedberg <[EMAIL PROTECTED]> wrote:
> I should have mentioned that I changed the HTML as well. I added an ID to
> the submit button (submit-member). Notice how the event is being triggered
> now: $('#submit-member').click(function() {...});
>

yes, I have that, and the event is happening - I can fire an alert or
set the html to a fixed string OK.

> Since var username = $(this).prev().val() is appearing inside the click
> method, $(this) refers to the submit button, prev() refers to the previous
> sibling of that button, which should be the text input, and val() refers to
> the value of that text input.
>

That's what I figured, but it doesn't seem to work. I always get null.
I'm trying to figure it out using FireBug and alert boxes and so on. I
realise this is not really a jquery issue though ... I think. More my
(lack of) knowledge about the DOM and js.

> Now I'm wondering, though, what you're trying to accomplish with the code.
> As Doug noted, it doesn't look like you really need a form at all to do what
> you're trying to do. But it's kind of hard to advise on that without knowing
> the larger context.
>

The context is that indeed, I don't need the submit behaviour here -
this is some admin code of my site, and I know I will always use
firefox and have javascript turned on. SO it's a good place to start
using some js/ajax techniques without yet worrying about how to make
things work for other browsers and users without js.

Once I have the text input being captured OK in the click method, I
will use it in a server call and then use it to set the html. one step
at a time though ...

-- 
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Karl Swedberg
I should have mentioned that I changed the HTML as well. I added an  
ID to the submit button (submit-member). Notice how the event is  
being triggered now: $('#submit-member').click(function() {...});


Since var username = $(this).prev().val() is appearing inside the  
click method, $(this) refers to the submit button, prev() refers to  
the previous sibling of that button, which should be the text input,  
and val() refers to the value of that text input.


Now I'm wondering, though, what you're trying to accomplish with the  
code. As Doug noted, it doesn't look like you really need a form at  
all to do what you're trying to do. But it's kind of hard to advise  
on that without knowing the larger context.


--Karl
_
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Jan 3, 2007, at 8:53 PM, Daniel McBrearty wrote:







$(document).ready(function() {
  $('#submit-member').click(function() {
var username = $(this).prev().val();
$("#member_info").html(username);
return false;
  });

});






Ok, I'm looking at this. I moved the js into a seperate file. I am
calling the function OK when the button is clicked. But something
seems wrong with

var username = $(this).prev().val();

which is ending up as undef.

I don't actually understand this line - how is it getting the value
out of the form? "this" seems to be the button itself.

I also tried something like

var username = $("#username").val();

to try to select the text box directly and get the value, but no  
joy either.


thanks again ... gonna sleep now :-)

--
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Doug Tabacco
True, but if it's not meant to be submittable, you could always just 
remove the form tags as well.

Klaus Hartl wrote:
> Doug Tabacco schrieb:
>> As several others have pointed out, the problem is that the form is 
>> submitting.  If that's not what you eventually want to happen, why not 
>> just make the submit input into a button input (type="button")?
> 
> I'm sure you will still be able to submit the form by hitting enter...
> 
> 
> -- Klaus
> 
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Daniel McBrearty
>
> 
> 
>  type="text/javascript">
> 
> $(document).ready(function() {
>   $('#submit-member').click(function() {
> var username = $(this).prev().val();
> $("#member_info").html(username);
> return false;
>   });
>
> });
>
> 
> 


Ok, I'm looking at this. I moved the js into a seperate file. I am
calling the function OK when the button is clicked. But something
seems wrong with

var username = $(this).prev().val();

which is ending up as undef.

I don't actually understand this line - how is it getting the value
out of the form? "this" seems to be the button itself.

I also tried something like

var username = $("#username").val();

to try to select the text box directly and get the value, but no joy either.

thanks again ... gonna sleep now :-)

-- 
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Klaus Hartl
Doug Tabacco schrieb:
> As several others have pointed out, the problem is that the form is 
> submitting.  If that's not what you eventually want to happen, why not 
> just make the submit input into a button input (type="button")?

I'm sure you will still be able to submit the form by hitting enter...


-- Klaus

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Doug Tabacco
As several others have pointed out, the problem is that the form is 
submitting.  If that's not what you eventually want to happen, why not 
just make the submit input into a button input (type="button")?

Daniel McBrearty wrote:
> Hi
> 
> Just getting into using js to do things. I'm just experimenting right now.
> 
> Here is my example code:
> 
> 
> 
> 
> 
>   function findMember(form){
> $("#member_info").html(form.username.value);
>   }
> 
> 
> 
>   
>value="Find by Username">
> 
> 
> now what happens when I fill in a value and click is that the value I
> entered into the text box appears in the "member_info"  ... but
> disappears again almost straight away.
> 
> any ideas?
> 
> thanks. the lib looks nice and clean BTW.
> 
> Daniel
> 

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Mike Alsup
> All your solutions don't take into account that IE6 will still submit
> the form if you hit enter

Good catch, Klaus.  As usual!

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Karl Swedberg

On Jan 3, 2007, at 8:05 PM, Klaus Hartl wrote:


All your solutions don't take into account that IE6 will still submit
the form if you hit enter - that was discussed a while back and here's
the test page for this:

http://stilbuero.de/demo/jquery/submit_test.html


-- Klaus


Good point, Klaus. I should have known...

--Karl
_
Karl Swedberg
www.englishrules.com
www.learningjquery.com



___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Daniel McBrearty
thanks a lot guys. That 's really a great response.

I got it to basically work, now I'll read through your suggestions and
clean it up. I'm still learning ... :-)

thanks again.

Daniel

On 1/4/07, Karl Swedberg <[EMAIL PROTECTED]> wrote:
> Okay, so Mike and Blair got back to you before I could, but I'm going to
> answer anyway.
>
> They're right, of course, that you need to return false, because you want to
> stop the default action.
>
> One of the great things about jQuery is that it lets you easily separate
> behavior from content. So I would suggest pulling the onclick handler out of
> the input. Here is what it would look like with the script in the ,
> but ideally you should put it in another file and include it the same way
> you include jquery.js:
>
> 
> 
>  type="text/javascript">
> 
> $(document).ready(function() {
>   $('#submit-member').click(function() {
> var username = $(this).prev().val();
> $("#member_info").html(username);
> return false;
>   });
>
> });
>
> 
> 
> 
>   
>
>   
> 
> 
>   
> 
> 
>
> You should also put DTD, etc. in there. I'm just taking shortcuts for the
> sake of brevity.
>
>
> --Karl
> _
> Karl Swedberg
> www.englishrules.com
> www.learningjquery.com
>
>
>
>
> On Jan 3, 2007, at 7:37 PM, Daniel McBrearty wrote:
>
> Hi
>
> Just getting into using js to do things. I'm just experimenting right now.
>
> Here is my example code:
>
>
> 
>
> 
>   function findMember(form){
> $("#member_info").html(form.username.value);
>   }
> 
>
> 
>   
>value="Find by Username">
> 
>
> now what happens when I fill in a value and click is that the value I
> entered into the text box appears in the "member_info"  ... but
> disappears again almost straight away.
>
> any ideas?
>
> thanks. the lib looks nice and clean BTW.
>
> Daniel
>
> --
> Daniel McBrearty
> email : danielmcbrearty at gmail.com
> www.engoi.com : the multi - language vocab trainer
> BTW : 0873928131
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>
>
>


-- 
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Klaus Hartl
Karl Swedberg schrieb:
> Okay, so Mike and Blair got back to you before I could, but I'm going to 
> answer anyway. 
> 
> They're right, of course, that you need to return false, because you 
> want to stop the default action.
> 
> One of the great things about jQuery is that it lets you easily separate 
> behavior from content. So I would suggest pulling the onclick handler 
> out of the input. Here is what it would look like with the script in the 
> , but ideally you should put it in another file and include it the 
> same way you include jquery.js:
> 
> 
> 
> 
> 
> $(document).ready(function() {
>   $('#submit-member').click(function() {
> var username = $(this).prev().val();
> $("#member_info").html(username);
> return false;
>   });
>
> });
> 
> 

All your solutions don't take into account that IE6 will still submit 
the form if you hit enter - that was discussed a while back and here's 
the test page for this:

http://stilbuero.de/demo/jquery/submit_test.html


-- Klaus

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Karl Swedberg
Okay, so Mike and Blair got back to you before I could, but I'm going  
to answer anyway.


They're right, of course, that you need to return false, because you  
want to stop the default action.


One of the great things about jQuery is that it lets you easily  
separate behavior from content. So I would suggest pulling the  
onclick handler out of the input. Here is what it would look like  
with the script in the , but ideally you should put it in  
another file and include it the same way you include jquery.js:






$(document).ready(function() {
  $('#submit-member').click(function() {
var username = $(this).prev().val();
$("#member_info").html(username);
return false;
  });

});




  

  



  



You should also put DTD, etc. in there. I'm just taking shortcuts for  
the sake of brevity.



--Karl
_
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Jan 3, 2007, at 7:37 PM, Daniel McBrearty wrote:


Hi

Just getting into using js to do things. I'm just experimenting  
right now.


Here is my example code:





  function findMember(form){
$("#member_info").html(form.username.value);
  }



  
  


now what happens when I fill in a value and click is that the value I
entered into the text box appears in the "member_info"  ... but
disappears again almost straight away.

any ideas?

thanks. the lib looks nice and clean BTW.

Daniel

--
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Klaus Hartl
Mike Alsup schrieb:
>> now what happens when I fill in a value and click is that the value I
>> entered into the text box appears in the "member_info"  ... but
>> disappears again almost straight away.
> 
> Try:   onclick="findMember(this.form); return false;"...
> 
> Without the "return false" in there you're going to submit the form.


I think you can still submit the form by hitting enter... at least in 
one or the other browser.


-- Klaus


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Klaus Hartl
Daniel McBrearty schrieb:
> Hi
> 
> Just getting into using js to do things. I'm just experimenting right now.
> 
> Here is my example code:
> 
> 
> 
> 
> 
>   function findMember(form){
> $("#member_info").html(form.username.value);
>   }
> 
> 
> 
>   
>value="Find by Username">
> 
> 
> now what happens when I fill in a value and click is that the value I
> entered into the text box appears in the "member_info"  ... but
> disappears again almost straight away.
> 
> any ideas?
> 
> thanks. the lib looks nice and clean BTW.


Yes, it's because the form gets submitted and the page gets immediatly 
reloaded. That takes a little while so you still can see the page before 
the refresh with the value put into the p.

A nice and clean solution would look like this:

* stop the form from submitting
* use proper events to catch all submits, not only clicking the submit 
button (you could hit enter in the form)
* don't pollute your HTML with inline event handler attributes.
* Do you really need the name attribute for the form? It's deprecated, 
you should use id as identifier and can leave away the method, GET is 
default.

Here's my proposal:



$(function {

 $('#find_member').submit(function() {
 var username = $('[EMAIL PROTECTED]"username"]', this).val();
 $('#member_info').html(username);
 return false;
 });

});



 
 




Cheers, Klaus


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Ⓙⓐⓚⓔ
it's a form.. it's submitting. you get a new page... it's gone! if you
target the form into an iframe you might get your desired results.

On 1/3/07, Daniel McBrearty <[EMAIL PROTECTED]> wrote:
> Hi
>
> Just getting into using js to do things. I'm just experimenting right now.
>
> Here is my example code:
>
>
> 
>
> 
>   function findMember(form){
> $("#member_info").html(form.username.value);
>   }
> 
>
> 
>   
>value="Find by Username">
> 
>
> now what happens when I fill in a value and click is that the value I
> entered into the text box appears in the "member_info"  ... but
> disappears again almost straight away.
>
> any ideas?
>
> thanks. the lib looks nice and clean BTW.
>
> Daniel
>
> --
> Daniel McBrearty
> email : danielmcbrearty at gmail.com
> www.engoi.com : the multi - language vocab trainer
> BTW : 0873928131
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>


-- 
Ⓙⓐⓚⓔ - יעקב   ʝǡǩȩ   ᎫᎪᏦᎬ
___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Blair McKenzie

I think the form may be submitting. The whole page is reloading when you
click submit. Try onClick="findMember(this.form; return false;".

Blair

On 1/4/07, Daniel McBrearty <[EMAIL PROTECTED]> wrote:


Hi

Just getting into using js to do things. I'm just experimenting right now.

Here is my example code:





  function findMember(form){
$("#member_info").html(form.username.value);
  }



  
  


now what happens when I fill in a value and click is that the value I
entered into the text box appears in the "member_info"  ... but
disappears again almost straight away.

any ideas?

thanks. the lib looks nice and clean BTW.

Daniel

--
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] noob q - using $().html

2007-01-03 Thread Mike Alsup
> now what happens when I fill in a value and click is that the value I
> entered into the text box appears in the "member_info"  ... but
> disappears again almost straight away.

Try:   onclick="findMember(this.form); return false;"...

Without the "return false" in there you're going to submit the form.

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


[jQuery] noob q - using $().html

2007-01-03 Thread Daniel McBrearty
Hi

Just getting into using js to do things. I'm just experimenting right now.

Here is my example code:





  function findMember(form){
$("#member_info").html(form.username.value);
  }



  
  


now what happens when I fill in a value and click is that the value I
entered into the text box appears in the "member_info"  ... but
disappears again almost straight away.

any ideas?

thanks. the lib looks nice and clean BTW.

Daniel

-- 
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/