bryankorno
asked on
pass textbox value via URL
I need to take the value that the user types into the textbox on an asp form and pass it via the URL. Here's the code:
function get_value(c_value, i)
{
i.text = c_value
}
table info...
<td><input name="txtCount" id="txtCount" type="text" size="3" onchange="javascript:get_v alue(txtCo unt.value, txtCount)" value="<%= dispRS.Fields("Quantity")% >" ></td>
<td><a HREF="./shopping.asp?actio n=update&a mp;item=<% =trim(disp RS.Fields( "Znum"))%> &count =txtCount) ">Update Quantity</a></td>
I know that "count=txtCount" doesn't work. Posting the form won't work b/c of hidden values needed in the form. I need help getting the textbox to show up in the url.
function get_value(c_value, i)
{
i.text = c_value
}
table info...
<td><input name="txtCount" id="txtCount" type="text" size="3" onchange="javascript:get_v
<td><a HREF="./shopping.asp?actio
I know that "count=txtCount" doesn't work. Posting the form won't work b/c of hidden values needed in the form. I need help getting the textbox to show up in the url.
try
function goTo(){
document.location = "./shopping.asp?action=upd ate&item=< %=trim(dis pRS.Fields ("Znum"))% >&count=" + document.forms[0].txtCount ;
}
<a HREF="javascript:goTo();"> Update Quantity</a>
function goTo(){
document.location = "./shopping.asp?action=upd
}
<a HREF="javascript:goTo();">
ASKER
damonf-
That's a great thought, but it's not pulling in the Znum or txtCount into the function. I tried changing it by adding the URL and the txtCount into the function. It seems to grab the correct value for Znum, but still no luck pulling in the txtCount. Maybe different syntax for the txtCount? Suggestions?
function goTo(url,c)
{
location.href = url + c
}
<td><a HREF="javascript:goTo('./s hopping.as p?action=u pdate& item=<%=di spRS.Field s("Znum")% >&coun t=', 'document.forms[0].txtCoun t');">Upda te Quantity</a></td>
That's a great thought, but it's not pulling in the Znum or txtCount into the function. I tried changing it by adding the URL and the txtCount into the function. It seems to grab the correct value for Znum, but still no luck pulling in the txtCount. Maybe different syntax for the txtCount? Suggestions?
function goTo(url,c)
{
location.href = url + c
}
<td><a HREF="javascript:goTo('./s
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that worked. I will definately issue points for that.
I do have another question that I will add another 20 points for.
I can update the quantity in that one textbox, but as soon as I add more products to the cart and try to update their respective quantities, the values of the textboxes becomes "undefined" after the submit.
The sql to update the db is still correct (updates only where znum=*product number*) and should work. I'm thinking that once more textboxes are added to the screen, document.forms[0].txtCount somehow becomes confused and doesn't know which textbox to update. I don't know why it would because all it does is run that sql.
I hope this makes sense. Help???
I do have another question that I will add another 20 points for.
I can update the quantity in that one textbox, but as soon as I add more products to the cart and try to update their respective quantities, the values of the textboxes becomes "undefined" after the submit.
The sql to update the db is still correct (updates only where znum=*product number*) and should work. I'm thinking that once more textboxes are added to the screen, document.forms[0].txtCount
I hope this makes sense. Help???
ASKER
that worked. I will definately issue points for that.
I do have another question that I will add another 20 points for.
I can update the quantity in that one textbox, but as soon as I add more products to the cart and try to update their respective quantities, the values of the textboxes becomes "undefined" after the submit.
The sql to update the db is still correct (updates only where znum=*product number*) and should work. I'm thinking that once more textboxes are added to the screen, document.forms[0].txtCount somehow becomes confused and doesn't know which textbox to update. I don't know why it would because all it does is run that sql.
I hope this makes sense. Help???
I do have another question that I will add another 20 points for.
I can update the quantity in that one textbox, but as soon as I add more products to the cart and try to update their respective quantities, the values of the textboxes becomes "undefined" after the submit.
The sql to update the db is still correct (updates only where znum=*product number*) and should work. I'm thinking that once more textboxes are added to the screen, document.forms[0].txtCount
I hope this makes sense. Help???
I might have a better picture if you sent me a code snippet where there's more than one field.
But I'll just take a stab at it:
if you have TWO fields called txtCount, document.forms[0].txtCount is undefined...it automatically becomes an array with one entry for each textbox, like so:
document.forms[0].txtCount [0].value
document.forms[0].txtCount [1].value
etc.
But I'll just take a stab at it:
if you have TWO fields called txtCount, document.forms[0].txtCount
document.forms[0].txtCount
document.forms[0].txtCount
etc.
ASKER
I'm doing a loop to display the records. When I add another record, it inserts the info to the db and then calls the data from the db to display the cart. Not the best way to do it but I don't need anything too fancy.
Do While Not dispRS.EOF
%>
<tr bgcolor="white">
<td><%=dispRS.Fields("Item ")%></td>
<td><%= dispRS.Fields("Description ") %></td>
<td><%=dispRS.Fields("Znum ")%></td>
<td><input name="txtCount" id="txtCount" type="text" size="3" maxlength="100" onfocus='this.select();' value="<%= dispRS.Fields("Quantity")% >" onchange="javascript:get_v alue(txtCo unt.value, txtCount)"></td>
<td ><a HREF="javascript:goTo('./s hopping.as p?action=u pdate& item=<%=tr im(dispRS. Fields("Zn um"))%>&am p;count=', document.forms[0].txtCount .value);"> Update Quantity</a></td>
<td><a HREF="./shopping.asp?actio n=del& item=<%= dispRS.Fields("Znum")%>">R emove Item</a></td>
</tr>
<%
dispRS.MoveNext
Loop
Do While Not dispRS.EOF
%>
<tr bgcolor="white">
<td><%=dispRS.Fields("Item
<td><%= dispRS.Fields("Description
<td><%=dispRS.Fields("Znum
<td><input name="txtCount" id="txtCount" type="text" size="3" maxlength="100" onfocus='this.select();' value="<%= dispRS.Fields("Quantity")%
<td ><a HREF="javascript:goTo('./s
<td><a HREF="./shopping.asp?actio
</tr>
<%
dispRS.MoveNext
Loop
ASKER
I'm doing a loop to display the records. When I add another record, it inserts the info to the db and then calls the data from the db to display the cart. Not the best way to do it but I don't need anything too fancy.
Do While Not dispRS.EOF
%>
<tr bgcolor="white">
<td><%=dispRS.Fields("Item ")%></td>
<td><%= dispRS.Fields("Description ") %></td>
<td><%=dispRS.Fields("Znum ")%></td>
<td><input name="txtCount" id="txtCount" type="text" size="3" maxlength="100" onfocus='this.select();' value="<%= dispRS.Fields("Quantity")% >" onchange="javascript:get_v alue(txtCo unt.value, txtCount)"></td>
<td ><a HREF="javascript:goTo('./s hopping.as p?action=u pdate& item=<%=tr im(dispRS. Fields("Zn um"))%>&am p;count=', document.forms[0].txtCount .value);"> Update Quantity</a></td>
<td><a HREF="./shopping.asp?actio n=del& item=<%= dispRS.Fields("Znum")%>">R emove Item</a></td>
</tr>
<%
dispRS.MoveNext
Loop
Do While Not dispRS.EOF
%>
<tr bgcolor="white">
<td><%=dispRS.Fields("Item
<td><%= dispRS.Fields("Description
<td><%=dispRS.Fields("Znum
<td><input name="txtCount" id="txtCount" type="text" size="3" maxlength="100" onfocus='this.select();' value="<%= dispRS.Fields("Quantity")%
<td ><a HREF="javascript:goTo('./s
<td><a HREF="./shopping.asp?actio
</tr>
<%
dispRS.MoveNext
Loop
ASKER
I'm doing a loop to display the records. When I add another record, it inserts the info to the db and then calls the data from the db to display the cart. Not the best way to do it but I don't need anything too fancy.
Do While Not dispRS.EOF
%>
<tr bgcolor="white">
<td><%=dispRS.Fields("Item ")%></td>
<td><%= dispRS.Fields("Description ") %></td>
<td><%=dispRS.Fields("Znum ")%></td>
<td><input name="txtCount" id="txtCount" type="text" size="3" maxlength="100" onfocus='this.select();' value="<%= dispRS.Fields("Quantity")% >" onchange="javascript:get_v alue(txtCo unt.value, txtCount)"></td>
<td ><a HREF="javascript:goTo('./s hopping.as p?action=u pdate& item=<%=tr im(dispRS. Fields("Zn um"))%>&am p;count=', document.forms[0].txtCount .value);"> Update Quantity</a></td>
<td><a HREF="./shopping.asp?actio n=del& item=<%= dispRS.Fields("Znum")%>">R emove Item</a></td>
</tr>
<%
dispRS.MoveNext
Loop
Do While Not dispRS.EOF
%>
<tr bgcolor="white">
<td><%=dispRS.Fields("Item
<td><%= dispRS.Fields("Description
<td><%=dispRS.Fields("Znum
<td><input name="txtCount" id="txtCount" type="text" size="3" maxlength="100" onfocus='this.select();' value="<%= dispRS.Fields("Quantity")%
<td ><a HREF="javascript:goTo('./s
<td><a HREF="./shopping.asp?actio
</tr>
<%
dispRS.MoveNext
Loop
ASKER
I'm doing a loop to display the records. When I add another record, it inserts the info to the db and then calls the data from the db to display the cart. Not the best way to do it but I don't need anything too fancy.
Do While Not dispRS.EOF
%>
<tr bgcolor="white">
<td><%=dispRS.Fields("Item ")%></td>
<td><%= dispRS.Fields("Description ") %></td>
<td><%=dispRS.Fields("Znum ")%></td>
<td><input name="txtCount" id="txtCount" type="text" size="3" maxlength="100" onfocus='this.select();' value="<%= dispRS.Fields("Quantity")% >" onchange="javascript:get_v alue(txtCo unt.value, txtCount)"></td>
<td ><a HREF="javascript:goTo('./s hopping.as p?action=u pdate& item=<%=tr im(dispRS. Fields("Zn um"))%>&am p;count=', document.forms[0].txtCount .value);"> Update Quantity</a></td>
<td><a HREF="./shopping.asp?actio n=del& item=<%= dispRS.Fields("Znum")%>">R emove Item</a></td>
</tr>
<%
dispRS.MoveNext
Loop
Do While Not dispRS.EOF
%>
<tr bgcolor="white">
<td><%=dispRS.Fields("Item
<td><%= dispRS.Fields("Description
<td><%=dispRS.Fields("Znum
<td><input name="txtCount" id="txtCount" type="text" size="3" maxlength="100" onfocus='this.select();' value="<%= dispRS.Fields("Quantity")%
<td ><a HREF="javascript:goTo('./s
<td><a HREF="./shopping.asp?actio
</tr>
<%
dispRS.MoveNext
Loop
If you want quick and dirty, just make each "count" field different, like so:
Do While Not dispRS.EOF
%>
<tr bgcolor="white">
<td><%=dispRS.Fields("Item ")%></td>
<td><%= dispRS.Fields("Description ") %></td>
<td><%=dispRS.Fields("Znum ")%></td>
<td><input name="txtCount<%=dispRS.Fi elds("Item ")%>" id="txtCount<%=dispRS.Fiel ds("Item") %>" type="text" size="3" maxlength="100" onfocus='this.select();' value="<%= dispRS.Fields("Quantity")% >" onchange="javascript:get_v alue(txtCo unt<%=disp RS.Fields( "Item")%>. value, txtCount<%=dispRS.Fields(" Item")%>)" ></td>
<td ><a HREF="javascript:goTo('./s hopping.as p?action=u pdate& item=<%=tr im(dispRS. Fields("Zn um"))%>&am p;count=', document.forms[0].txtCount <%=dispRS. Fields("It em")%>.val ue);">Upda te Quantity</a></td>
<td><a HREF="./shopping.asp?actio n=del& item=<%= dispRS.Fields("Znum")%>">R emove Item</a></td>
</tr>
<%
dispRS.MoveNext
Loop
BTW, do you still need to call get_value onchange? I think we're taking care of that with the link....whenever you click the link it will use the current value.
Do While Not dispRS.EOF
%>
<tr bgcolor="white">
<td><%=dispRS.Fields("Item
<td><%= dispRS.Fields("Description
<td><%=dispRS.Fields("Znum
<td><input name="txtCount<%=dispRS.Fi
<td ><a HREF="javascript:goTo('./s
<td><a HREF="./shopping.asp?actio
</tr>
<%
dispRS.MoveNext
Loop
BTW, do you still need to call get_value onchange? I think we're taking care of that with the link....whenever you click the link it will use the current value.
ASKER
I took out the onchange function, and changed <%dispRS.Fields("Item")%> to <%=trim(dispRS.Fields("Znu m"))%> because "Znum" is the unique value.
Works great! Thanks!!! I want to give you the extra points I promised you. Do I have to contact the admin, or can I do that myself through my account page?
Works great! Thanks!!! I want to give you the extra points I promised you. Do I have to contact the admin, or can I do that myself through my account page?
Just post a question "points for damonf" and I'll answer it.
ASKER
done
<Script language = "Javascript">
function validate(frm) {
if (frm.txtCount.value == "") {
alert("Please enter a value.");
frm.txtCount.focus();
return false;
}
frm.action = "process.asp?id="+frm.txtC
alert(frm.action);
return true;
}
</script>
<form name="form1" method="post" action="aa.asp" onsubmit="return validate(this)">
<input type="text" name="txtCount">
<input type="submit" name="Submit" value="Submit">
</form>