0

I need to make this code set "str" as "Recent" if the "str" got no value.
Right now i have to use this:

<form>
<select name="users" onChange="showUser(this.value)">
<option value="">Select album:</option>
<option value="Recent">Somealbumname</option>
</select>
</form>

but its really annoying to have to use the select, i want the code to load with the "str" as "Recent" if its not declared already.

<script type="text/javascript">
function showUser(str)
{

if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","xxxx/xxxx.php?q="+str,true);
xmlhttp.send();
}
</script>
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Taywin
0

If you want it that way, then you need to modify the page you are displaying, not Ajax part. You just load the "Recent" data to the page and remove the "Select Album" option from the list.

0

Do you mean something like <body onload="showUser(this.value)"> ?
im not sure how i should make the ajax run with str as "Recent"

0

Nope, you don't need to call Ajax when you first load the page. You just simply load the value ready for "Recent" and display it on the page. Then you could get rid of "Select Album" option and let the select tag on "Recent" option.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.