C# code for searching, help needed

L

Lair Lair

How can I change this code to reflect just one textbox for searching for
firstname and lastname insead of having separate textboxes. Is this
possible?

Thank you.


<script language="javascript">
//function to handle enter on keyboard
function txtWildPeopleFinder_KeyDown(e)
{
if (e.keyCode == 13 || e.keyCode==10)
{
e.returnValue=false;
DoWildPeopleSearch();
return false;
}
else
return true;
}
//escape apostrophes in search strings
function escapestr(str)
{
return str.replace("'","%22");
}

//search function
function DoWildPeopleSearch()
{
var firstname = escapestr(document.all["firstname"].value);
var lastname = escapestr(document.all["lastname"].value);
var url;

//search on last name
if(firstname == "")
{
url = "/searchcenter/Pages/peopleresults.aspx?k=LastName%3A" +
lastname;
window.location=url;
return;
}

//search on first name
if(lastname == "")
{
url = "/searchcenter/Pages/peopleresults.aspx?k=FirstName%3A" +
firstname;
window.location=url;
return;
}

//first and last
url = "/searchcenter/Pages/peopleresults.aspx?k=lastname%3A" + lastname
+ "%20FirstName%3A" + firstname;
window.location=url;
return;
}
</script>

<table cellpadding="3" cellspacing="0" border="0" width="100%"
ID="Table3">
<tr>
<td width="80" nowrap>
First Name:
</td>
<td width="100%">
<input size="10" maxlength="100" id="firstname" name="firstname"
type="text" onkeydown="txtWildPeopleFinder_KeyDown(event)">
</td>
</tr>
<tr>
<td width="80" nowrap>
Last Name:
</td>
<td>
<input size="10" maxlength="100" id="lastname" name="lastname"
type="text" onkeydown="txtWildPeopleFinder_KeyDown(event)">
</td>
<tr>
<td>
<input type="button" onclick="DoWildPeopleSearch()" value="Search">
</td>

</tr>
</tr>
</table>
 
M

Michaela Julia

Lair said:
How can I change this code to reflect just one textbox for searching for
firstname and lastname insead of having separate textboxes. Is this
possible?

How about this:
Use a dropdown listbox with items like "find in first name", "find in
last name", "find in first and last name" and change your if-block (or
use a switch) accordingly.
Checkboxes might be nice too. Depends on the layout of your form.
 
P

Pavel Minaev

How can I change this code to reflect just one textbox for searching for
firstname and lastname insead of having separate textboxes. Is this
possible?

Thank you.

<script language="javascript">

This is a group about the C# programming language, not about
JavaScript.
 

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

Top