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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get data from a combo box via javascript 2

Status
Not open for further replies.

dpk136

MIS
Joined
Jan 15, 2004
Messages
335
Location
US
i have a datagrid that i made in ASP, in each row there is a dropdown to change one of the fields, i have named it ShipMethod'i', where 'i' is the line number so the first one would be ShipMethod1. When i click on a link in that row, it passes the name ShipMethod1 and the FreightID. For some reason, it says that ShipMethod1 is undefined.

HEre is my code
getting passed in is
ShipDropDown = ShipMethod1
FreightReportID = 2809
Code:
function ConfirmShipMeth(ShipDropDown,FreightReportID) {
  var ShipMethod= document.forms['myForm'].elements[ShipDropDown].options[document.forms['myForm'].elements[ShipDropDown].selectedIndex].value;
  if (ShipMethod !== "") {
    if (confirm("Are you sure you would like to confirm this Shipment Method?") == 1) {
      window.location="ConfirmShipMeth.asp?ShipMethod=" + ShipMethod + "&FreightReportID=" + FreightReportID;
    }
  }
}

David Kuhn
------------------
 
Code:
holdThis = "ShipMethod" & i
Response.Write("<td><a href='javascript:ConfirmShipMeth(" & holdThis & "," & strFreightReportID & ")'>Confirm</a></td>")

David Kuhn
------------------
 
since this is a javascript forum, it really would be beneficial for us if you post the client-side code. in other words, the code as it appears in a view > source.

however, it seems you need single-quotes:

Code:
holdThis = "ShipMethod" & i
Response.Write("<td><a href='javascript:ConfirmShipMeth([red]'[/red]" & holdThis & "[red]'[/red]," & strFreightReportID & ")'>Confirm</a></td>")



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Depends on whether or not you're using JScript or VBScript. Since s/he's attempting concatenation with the ampersand:
Code:
holdThis = "ShipMethod" & i
it's reasonable to assume VBScript - in which case you would double up your quotes like cory suggested.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
actually not, I'm just really freakin bored

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Why would i need double quotes...i'm passing in a variable of what the dropdown is called, not the value that is selected. that is what i want the javascript to do.

the ShipMethod1 goes in fine to the JavaScript, i have another script in which i do this for a textbox, and that works. i just don't know why it's not calling that element on the form.

David Kuhn
------------------
 
[1] Main thing.

>Response.Write("<td><a href='javascript:ConfirmShipMeth(" & holdThis & "," & strFreightReportID & ")'>Confirm</a></td>")

[tt]Response.Write("<td><a href='javascript:ConfirmShipMeth([red]""[/red]" & holdThis & "[red]""[/red],[red]""[/red]" & strFreightReportID & "[red]""[/red])'>Confirm</a></td>")[/tt]

[2] Minor things

[2.1] "!==" is uncommon, though work. Orthodox form is "!=".

>if (ShipMethod !== "") {
Better this.
[tt]if (ShipMethod != "") {[/tt]

[2.2] true==1 works but very unorthodox, hence, confusing to reader/writer. true is represented as -1, but in this expression, curiously, it works. Better simply outright.

>if (confirm("Are you sure you would like to confirm this Shipment Method?") == 1) {
Better this.
[tt]if (confirm("Are you sure you would like to confirm this Shipment Method?")) {[/tt]

[2.3]

>var ShipMethod= document.forms['myForm'].elements[ShipDropDown].options[document.forms['myForm'].elements[ShipDropDown].selectedIndex].value;
Simply this.
[tt]var ShipMethod= document.forms['myForm'].elements[ShipDropDown].value;[/tt]

 
A combo of point 1 and 2.3 made this work. i put both in and it worked. thanks for the help and tips on the other parts too.

David Kuhn
------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top