...

View Full Version : Javascript OnBlur() - Add to QueryString



JimboF
05-06-2004, 05:05 PM
Hi All,

I was wondering if it is possible to use Javascript to add the value from a form textbox field to the QueryString, perhaps using the OnBlur event?

Basically, I'm looking for something similar to the dropdown box system that uses the OnChange event to redirect to a url assigned to the selected dropdown value. Can this be done with a textbox field, rather than a dropdown?

Example code would be welcomed. :)

Thanks,
JimboF

Kor
05-06-2004, 06:01 PM
is it this of any help? (Frankly, I didn't uderstand the onblur ideea)
[php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<script>
function gourl(a){
alert(a);
location.href='http://'+a;
}
</script>
</head>
<body>
<form>
http://<input name="url" type="text"><input type="button" value="Go URL" onclick="gourl(this.form.url.value)">
</form>
</body>
</html>

Kor
05-06-2004, 06:01 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<script>
function gourl(a){
alert(a);
location.href='http://'+a;
}
</script>
</head>
<body>
<form>
http://<input name="url" type="text"><input type="button" value="Go URL" onclick="gourl(this.form.url.value)">
</form>
</body>
</html>

JimboF
05-06-2004, 06:40 PM
Kor,

Thanks for the suggestion but not quite what I was looking for. I'll try to explain myself a little better below.

For example I have the folowing search form:

<form name="SearchDB" method="GET" action="Search.asp">
<tr>
<td valign="middle" width="136"><font size="2" face="Verdana"><b>Keyword(s):</b></font></td>
<td valign="middle" width="314"><input type="text" name="keywords" size="30"></td>
</tr>
</form>

What I would like to happen is:

1) someone enters in a keyword into the keywords form field to search the database.

2) after they move the cursor to another part of the form (i.e., there are other options that can be selected on the search form) then the keyword(s) are automatically added to the QueryString with out the user doing anything (i.e., through a page refresh triggered by an OnBlur event perhaps).

Essentially, what I'm looking for is a javascript that will grab the keyword value, add it to a URL string + the QueryString variable (something like Search.asp?keywords=Thanks for the help&records=1") and then refresh the page with this new URL.

Below is the similar Dropdown box code I mentioned in the previous post:

<select size="1" name="records" onChange="window.location=document.Records.records.options[document.Records.records.selectedIndex].value">
<option value="Search.asp?keywords=&records=">Choose One</option>
<option value="Search.asp?kewyords=&records=25" <% If Request.QueryString("records") = "25" Then Response.Write " selected" End If%>>25</option>
<option value="Search.asp?keywords=&records=50" <% If Request.QueryString("records") = "50" Then Response.Write " selected" End If%>>50</option>
</select>

What happens here is that when an option is selected, say 25, then the OnChange event jumps to the URL given in the Option Value, thus updating the Querystring with the correct value for "records".

Is something similar possible for a Textbox?

Thanks for the help!

Cheers,
JimboF

JimboF
05-06-2004, 09:26 PM
I played around a little bit with this and the following seems to work. Thought I would post it in case anyone else is interested.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Database Search</title>

<script language="JavaScript">
function KeyWdQS(){
var key=document.SearchDB.keywords.value
if(key != "") {
url="Search.asp?keywords=" + key
document.location.href=url;}
}
</script>
</head>

<body>
<form name="SearchDB" method="GET" action="Search.asp">
<tr>
<td width="36" valign="middle"><b> <font size="2" face="Verdana">
Keyword(s</font><font size="2" face="Verdana">):</font></b></td>
<td valign="middle" width="314">
<input type="text" name="keywords" size="30" onblur="javascript:KeyWdQS()"></td>
<td valign="middle" width="36">&nbsp;</td>
</tr>
</form>
</body>
</html>

Cheers,



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum