[jQuery] Re: Newb question about accessing a form's inputs

2009-02-07 Thread Kevin Dalman

Unless jQuery 1.3 has made vast improvement in the name=Xxx
functionality, it is *horrendously slow*! I use a custom function to
access form-fields - $F(fieldName) - which is up to 1000-times
faster on large pages in my web-application. But this method is
dependant on other custom methods, so I cannot provide it here as a
stand-alone plug-in..

I wish/hope jQuery will soon provide an efficient way to access form-
fields 'by name' because using IDs on form-fields is a clumsy hack
that I refuse to use except in special cases. On complex, dynamically
generated form pages, it clutters the code and requires extra logic to
add sequential IDs to things like radio buttons. So this is not a
proper solution to a common need.

/Kevin

On Feb 6, 2:27 pm, James james.gp@gmail.com wrote:
 Without using IDs, you can use:

 var myVar = $(input[name=myHiddenInput]).val();

 On Feb 6, 10:54 am, james noahk...@gmail.com wrote:



  Hi,

  If I have a form:

  form name=myForm method=post action=myAction.php
  onsubmit=javascript:doStuff()
      input type=hidden name=myHiddenInput/
      input type=text name=myNonHiddenText/
      input type=submit value=submit
  /form

  What is the equivalent JQuery syntax for the following?

  function doStuff() {
          document.myForm.myHiddenInput.value = 'some dynamic var';
          return true;

  }

  Thanks in advance,
  James- Hide quoted text -

 - Show quoted text -


[jQuery] Re: Newb question about accessing a form's inputs

2009-02-06 Thread sem101

Always give your elements id's (instead of name values) -- or at least
a class attribute, so they can be targeted. (You can target name
values, but it's a bit more work.)

Examples:

input type=hidden id=myHiddenInput  name=myHiddenInput
class=attribute1 /
input type=text id=myNonHiddenText name=myNonHiddenText
class=attribute1 /

var myHiddenInput = $('#myHiddenInput').val();
var myNonHiddenText = $('#myNonHiddenText').val();

$(form#myForm).ajaxForm({
 url: myAction.php,
 type: POST
});

http://docs.jquery.com/Val
http://malsup.com/jquery/form/

On Feb 6, 3:54 pm, james noahk...@gmail.com wrote:
 Hi,

 If I have a form:

 form name=myForm method=post action=myAction.php
 onsubmit=javascript:doStuff()
     input type=hidden name=myHiddenInput/
     input type=text name=myNonHiddenText/
     input type=submit value=submit
 /form

 What is the equivalent JQuery syntax for the following?

 function doStuff() {
         document.myForm.myHiddenInput.value = 'some dynamic var';
         return true;

 }

 Thanks in advance,
 James


[jQuery] Re: Newb question about accessing a form's inputs

2009-02-06 Thread James

Without using IDs, you can use:

var myVar = $(input[name=myHiddenInput]).val();

On Feb 6, 10:54 am, james noahk...@gmail.com wrote:
 Hi,

 If I have a form:

 form name=myForm method=post action=myAction.php
 onsubmit=javascript:doStuff()
     input type=hidden name=myHiddenInput/
     input type=text name=myNonHiddenText/
     input type=submit value=submit
 /form

 What is the equivalent JQuery syntax for the following?

 function doStuff() {
         document.myForm.myHiddenInput.value = 'some dynamic var';
         return true;

 }

 Thanks in advance,
 James


[jQuery] Re: Newb question about accessing a form's inputs

2009-02-06 Thread james

Beauty. That's what I was looking for.

And thanks to the point to the docs.



On Feb 6, 4:09 pm, sem101 semiotics...@gmail.com wrote:
 Always give your elements id's (instead of name values) -- or at least
 a class attribute, so they can be targeted. (You can target name
 values, but it's a bit more work.)

 Examples:

 input type=hidden id=myHiddenInput  name=myHiddenInput
 class=attribute1 /
 input type=text id=myNonHiddenText name=myNonHiddenText
 class=attribute1 /

 var myHiddenInput = $('#myHiddenInput').val();
 var myNonHiddenText = $('#myNonHiddenText').val();

 $(form#myForm).ajaxForm({
  url: myAction.php,
  type: POST

 });

 http://docs.jquery.com/Valhttp://malsup.com/jquery/form/

 On Feb 6, 3:54 pm, james noahk...@gmail.com wrote:

  Hi,

  If I have a form:

  form name=myForm method=post action=myAction.php
  onsubmit=javascript:doStuff()
      input type=hidden name=myHiddenInput/
      input type=text name=myNonHiddenText/
      input type=submit value=submit
  /form

  What is the equivalent JQuery syntax for the following?

  function doStuff() {
          document.myForm.myHiddenInput.value = 'some dynamic var';
          return true;

  }

  Thanks in advance,
  James