Click to See Complete Forum and Search --> : this.options[this.selectedIndex].value not working


seotool
03-05-2009, 03:01 AM
Hello,

I have an asp.net website and my page isn't doing what it's supposed to do and I"d really like to get this fixed:

+this.options[this.selectedIndex].value is supposed to slot into a url the name of the database (mysql) which is selected from the drop down box as soon as the user makes the selection.

There are two functions becuase the database name can be input into a textbox if my site is unable to connect to the database on their server.
+this.options[this.selectedIndex].text+ used to be .value instead of .text. I read that .value just returns the number of the index, and to get the actual name of the database, use .text. Am I correct? I doesn't work. The 2 functions and the output which I've taken from the page source code are below:

function loadFrm(){
if (this.options[this.selectedIndex].text!=""){
setMsg('create', 'Saving MySQL database details...')
document.getElementById('hdnFrm').style.display='none';
url="<%=hdnPath.value%>/admin/gen.php?host=<%=tbServer.text%>&uid=<%=tbUserName.text%>&pwd=<%=tbPasswrod.text%>&db="+this.options[this.selectedIndex].text+"&url=<%=hdnLinkURL.value%>&title=<%=hdnLinkTitle.value%>&desc=<%=hdnLinkDesc.value%>";
//alert(url);
document.getElementById('hdnFrm').src=url;
}
else{
document.getElementById('hdnFrm').style.display='none';
}
//document.getElementById('myframe').src='http://'+this.options[this.selectedindex].text;
return false;
}//end function

function loadFrm2(){
if (this.value!=""){
setMsg('create', 'Saving MySQL database details...')
document.getElementById('hdnFrm').style.display='none';
url="<%=hdnPath.Value%>/admin/gen.php?host=<%=tbServer.text%>&uid=<%=tbUserName.text%>&pwd=<%=tbPasswrod.text%>&db="+this.value+"&url=<%=hdnLinkURL.value%>&title=<%=hdnLinkTitle.value%>&desc=<%=hdnLinkDesc.value%>";
//alert('<%=lstAdvanceSites.SelectedItem.Text%>');
document.getElementById('hdnFrm').src=url;
}
else{
document.getElementById('hdnFrm').style.display='none';
}
//document.getElementById('myframe').src='http://'+this.options[this.selectedindex].text;
return false;
}//end function
</script>

Output:
<script type="text/javascript">
var firstTime=1
var url

function setMsg(id, txt){
if(id && id=='create')
firstTime=0;

if (!firstTime)
document.getElementById('ctl00_PageContents_lblMsg').innerHTML=txt;

}//end function

//
function loadFrm(){
if (document.getElementById('hdnFrm').style.display='none';
url="http://www.mortgage-pros.com/links/admin/gen.php?host=mortgage-pros.com&uid=mortpros_sking&pwd=pianos1234&db="+this.options[this.selectedIndex].text+"&url=http://www.mortgage-pros.com&title=California Mortgages&desc=Pacific West Capital is a full service California mortgage broker approved with over 100 lenders and funding in 50 states for residential and commercial mortgages. Purchase and refinance mortgages are available with low rates, low fees and top notch processing.";
!=""){
setMsg('create', 'Saving MySQL database details...')
document.getElementById('hdnFrm').style.display='none';
url="http://www.mortgage-pros.com/links/admin/gen.php?host=mortgage-pros.com&uid=mortpros_sking&pwd=pianos4&db="+this.options[this.selectedIndex].text+"&url=http://www.mortgage-pros.com&title=California Mortgages&desc=Pacific West Capital is a full service California mortgage broker approved with over 100 lenders and funding in 50 states for residential and commercial mortgages. Purchase and refinance mortgages are available with low rates, low fees and top notch processing.";
//alert(url);
document.getElementById('hdnFrm').src=url;
}
else{
document.getElementById('hdnFrm').style.display='none';
}
//document.getElementById('myframe').src='http://'+this.options[this.selectedindex].text;
return false;
}//end function

function loadFrm2(){
if (this.value!=""){
setMsg('create', 'Saving MySQL database details...')
document.getElementById('hdnFrm').style.display='none';
url="http://www.mortgage-pros.com/links/admin/gen.php?host=mortgage-pros.com&uid=mortpros_sking&pwd=pianos14&db="+this.value+"&url=http://www.mortgage-pros.com&title=California Mortgages&desc=Pacific West Capital is a full service California mortgage broker approved with over 100 lenders and funding in 50 states for residential and commercial mortgages. Purchase and refinance mortgages are available with low rates, low fees and top notch processing.";
//alert('www.mortgage-pros.com');
document.getElementById('hdnFrm').src=url;
}
else{
document.getElementById('hdnFrm').style.display='none';
}
//document.getElementById('myframe').src='http://'+this.options[this.selectedindex].text;
return false;
}//end function
</script>

As you can see, this.value is supposed to have the textbox value, and this.options[this.selectedIndex].text+ is putting the literal text as the name for the database.

here is the dropdown list from farther down the page:

<asp:DropDownList ID="lstDatabase" runat="server" />

<asp:Button ID="btnFillDb" runat="server" Text="Fill Databases" Width="83px" ValidationGroup="db" />

OR write DB Name here: <asp:TextBox ID="tbDbName" runat="server" />

<script type="text/javascript">
document.getElementById('<%=lstDatabase.ClientID%>').onchange=loadFrm;
document.getElementById('<%=tbDbName.ClientID%>').onchange=loadFrm2;
</script>

Can someone please help me get this working? I'd really like to understand why the text from the dropdown list or the text from the textbox when input isn't sending the info to the function. The function does fire.

Fang
03-05-2009, 03:19 AM
this.options[this.selectedIndex].value can only be used in an event in the select element. Use the full reference when inserting it into a string in a function.
document.formName.selectName.options[document.formName.selectName.selectedIndex].value
This assumes the value attribute has been set in the options.

seotool
03-05-2009, 03:33 AM
this.options[this.selectedIndex].value can only be used in an event in the select element. Use the full reference when inserting it into a string in a function.
document.formName.selectName.options[document.formName.selectName.selectedIndex].value
This assumes the value attribute has been set in the options.

Hi,

Thanks for your speedy response. Pardon my newbieness at javascript. How do I determine the formname ? document.formname and the selectname?
<asp:DropDownList ID="lstDatabase" runat="server"> I assume the selectname is lstDatabase?
Also, my aspx page is not using a form like <form name="formulario" enctype="multipart/form-data"> Everything on the page is within the <asp:Content ID="Content3" ContentPlaceHolderID="PageContents" Runat="Server"> tags. is Content3 my form? document.Content3.lstDatabase.options[document.Content3.lstDatabase.selectedindex].value ?

url="http://www.scotking.com/links/admin/gen.php?host=scotking.com&uid=scotking_ski&pwd=pia9&db="+document.Content3.lstDatabase.options[document.Content3.lstDatabase.selectedindex].value+"&url=http://www.scotking.com&title=Scot King | Virtuoso Pianist&desc=Scot King is a master pianist who has played the piano since he was 6. He performs the complete etudes of Frederic Chopin at his website. One of the great American pianist of our time.";
//alert('www.scotking.com');

As you can see, that didn't work..

seotool
03-05-2009, 09:41 PM
I stand corrected. I DID work. You're response is also incorrect. I don't need to use the full path in a function.