Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selected Value for drop down, Help Please....

Status
Not open for further replies.

SuperCyber

Programmer
Aug 10, 2001
35
US
I am beating my haed against the wall ive tried everything i can think of and still i cant grab the value of this dropdown. Any help is greatly appreciated.

Brian

varID = document.form.PHY_1.options(document.form.PHY_1.options.selectedIndex).value
 
Brian,

I'm assuming that's a JavaScript line. I see two areas of concern here. First, I don't think you're referencing the form object properly. You can reference that object by name like this.
Code:
<form name=&quot;myform&quot; ...>
Then your JavaScript line would look like this.
Code:
document.myform.elementname...
Or you can reference it by index number with zero being the first form on the page. If you only have one form on the page, then you would reference it with a zero index like this.
Code:
document.forms[0].elementname...
The second thing I see is that you need to use square brackets instead of parentheses when you set the index of the drop down and you don't need to use the options reference when getting the selectedIndex. Here's a complete example.
Code:
varID = document.myform.PHY_1.options[document.myform.PHY_1.selectedIndex].value


<form name=&quot;myform&quot;>
  <select name=&quot;PHY_1&quot;>
    <option value=&quot;something&quot;>Something</option>
    <option value=&quot;somethingelse&quot;>Something Else</option>
  </select>
</form>

ToddWW
 
I am using a javascript onClick command to issue the new request each time the value changes. Then I am running asp code inside the javascript code to pull the value of the selected dropdown item and then pass it to my SQL SP. Then once I get the return values I pass them back to the javascript to populate span tags. It all works if i manually input a value for varID, but then what would be the point. If I could find a way to call the SQL SP from javascript or pass the value to VBScript from Javascript, then this would be a non issue. Below is the error i am receiveing and the code sniplet.

Thanks for your help,
Brian


I get this error when calling from VBscript:

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/APS-Online/Customer/aaa.asp, line 17, column 45
varID = document.ClientErrCheck.PHY_1.options[document.ClientErrCheck.PHY_1.selectedIndex].value
--------------------------------------------^


Code snip:


<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--

function PHY_1_onchange() {

if (!(document.ClientErrCheck.PHY_1.selectedIndex == &quot;&quot;)){

<%
Dim varID, strAddress

varID = document.ClientErrCheck.PHY_1.options[document.ClientErrCheck.PHY_1.selectedIndex].value

&quot;....SQL stored procedure.....
Set prm1 = cmdGetCust.CreateParameter(&quot;@ID&quot;,adInteger,adParamInput,,varID)
cmdGetCust.Parameters.Append prm1
Set prm5 = cmdGetCust.CreateParameter(&quot;@Address&quot;,adVarChar,adParamOutput,50,strAddress)
cmdGetCust.Parameters.Append prm5
&quot;

Response.write &quot;var varAddress = &quot; & chr(34) & strAddress & chr(34) & &quot;;&quot;
%>

window.ADD_1.innerText = varAddress

}
}

//-->
</SCRIPT>



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top