![]() |
get value of name attribute
so I have an object of an input element which I am trying to get the value of its name attribute. From here I am looking to get the value of the text in the input field itself. I guess I could always skip straight to grabbing the value of the input, but ohwell
Here is the code I have: so far my alert() is returning undefined Code:
var patt = new RegExp('/^[A-Za-z0-9@.]$/',modifiers);Thanks a lot |
This code makes no sense.
The name of an <input> field is simply a string. So when you do input_id.getAttribute("name") that gives you a string.You can *NOT* then get the .value attribute of a string. Strings don't have a .value attribute. On top of that, the name of an <input> field is determined by the HTML coder. As in: Code:
<input type="text" id="zamboni" name="widget" />I think you are very very badly confused. |
Maybe you should describe, in words, what you are trying to do. Don't show us random code. Just describe the problem.
|
The point of .getAttribute() is to get the specified attribute of the html element in question. I looked it up and found that it gets the value of it already so I can drop the .value portion of it. I am used to defining .value for these kinds of things to get the value.
I am not trying to validate the value of the name attribute, I am trying validate the value of the input element. I have lots of input elements and I need to identify which input has been targeted, thats why I get the name attribute first. // var input = document.getElementsByName(name).value;currently its commented out, but I will be uncommenting it so as to get the value of the input field after targeting it with the getElementsByName(name). After this I would validate. |
Code:
var input = document.getElementsByName(name).value;getElementsByName() returns an *ARRAY* of all elements on the page with that name. Even if there is only one by that name. So if you *KNOW* there is only one by that name: Code:
var input = document.getElementsByName(name)[0].value;********** Almost always, a better way to do this is to use the <form> to reference its member <input>s. Example HTML: Code:
<form id="myForm">Code:
var form = document.getElementById("myForm"); |
| All times are GMT +1. The time now is 04:02 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.