find values of text field without using a form

K

Kevin Blount

I have reason to use a text field outside of a <form> tag, but I'm
having trouble checking the value of the form. The idea is to grab the
field value and append it to a redirect.

The problem is I can't get the field value. Here's the code I'm trying
to use:

in my .aspx page:
<td width="140"><input type="text" name="searchString"
id="SearchString" class="smallFont" style="width: 135px;" /></td>
<td width="25" align="right"><input type="image" name="searchButton"
id="searchButton" src="/_images/goButton.gif" onclick="submitSearch()"
/></td>

in my .js file:

function submitSearch() {
alert(document.getElementById('searchString').value);
}

When i click the searchButton image, I get the following javascript
error:
Error: document.getElementById("searchString") has no properties

any ideas?? I've checked multiple websites and believe this is the
right method of doing this, but well.. I get the error.
 
M

Martin Honnen

Kevin Blount wrote:

<td width="140"><input type="text" name="searchString"
id="SearchString" class="smallFont" style="width: 135px;" /></td>
^^^^^^^^^^^^
If the id is "SearchString" then you need to pass exactly that to
alert(document.getElementById('searchString').value);

getElementById, but you pass in "searchString".
 
K

Kevin Blount

Thanks Martin. Tis was a case of looking at it too long. I know that
JavaScript (and C#.NET which I'm also writing in) is case sensitive...
I just didn't even spot that I had an upper S for the ID.. it's weird,
as I never start field names/IDs with upper case letters, so I guess I
didn't think of looking at this one, especially as "name" is the
correct case.

cheers :)

Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,434
Messages
2,571,685
Members
48,796
Latest member
Greg L.

Latest Threads

Top