Reputation: 5463
I have this part of my form:
<input name="myName" type="text" value="myValue">
My questions are:
Upvotes: 1
Views: 100
Reputation: 168
It's simple like CSS to read the textfield parameter.
use the jquery command to get their values..
here's my example :
$('object_parameter').val();
easier.
Upvotes: 0
Reputation: 48455
Here is one option...
var value = $("[name=''.$id.'']").attr("value");
To work with external JS file...
in JS file:
var knownID;
function SetID(id){
knownID = id;
}
function UsingValue(){
var value = $("[name='" + knownID + "']").attr("value");
}
in PHP page (javascript function on page load):
SetID(.$id.); //not sure the correct syntax for PHP rendering
Though I would just prefer to do my JavaScript on the PHP page, if I need some heavy functions I would pass the element to the JS file to be used
Upvotes: 0
Reputation: 3502
What you have written is a bit odd. Are you also using php as well? Why the dots, inverted commas, and the dollar sign as your id and value?
In any event
<input id="id" name="id" type="text" value="textvalue">
you should use the .val()
function.
$('#id').val();
Upvotes: 0
Reputation: 12630
Probably something like:
$('input[name="name-of-input"]')
And then you can extract the value using:
var v = $('input[name="name-of-input"]').val();
If you want to get a list of names of input elements on your page then you'll need to add a bit more, e.g. to enumerate the tags and output their names:
$('input[type="text"]').each(function (idx, elem) {
alert($(elem).attr('name'));
});
You could make this more specific by adding a class
attribute to the inputs you want to examine (in it's current form the code above will look at ALL textboxes on the page).
Upvotes: 1
Reputation: 3502
If @mdm is correct (and I think he is) your question is not sufficiently detailed to give the full answer.
If there is some event triggered such as an onfocus
which you want to trigger an action than you could conceivably use the this.id
selector to dynamically get your element's ID but because you have not posted the full code it is not possble to show you how this would work.
Upvotes: 0
Reputation: 10680
You'll need to use attribute selection.
e.g.
$('input[name="NameYouAreLookingFor"]');
http://api.jquery.com/attribute-equals-selector/
Upvotes: 0
Reputation: 38345
Use the attribute equals selector like so: $('input[name="name"]')
.
Upvotes: 0
Reputation: 21947
You can use selector by attribute:
$('input[name="myname"]');
Upvotes: 0