Link to home
Start Free TrialLog in
Avatar of bryankorno
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_value(txtCount.value, txtCount)" value="<%= dispRS.Fields("Quantity")%>" ></td>

<td><a HREF="./shopping.asp?action=update&amp;item=<%=trim(dispRS.Fields("Znum"))%>&amp;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.  
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

In your form:

<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.txtCount.value;
     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>
Avatar of damonf
damonf

try

function goTo(){
  document.location = "./shopping.asp?action=update&item=<%=trim(dispRS.Fields("Znum"))%>&count=" + document.forms[0].txtCount;
}

<a HREF="javascript:goTo();">Update Quantity</a>
Avatar of bryankorno

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('./shopping.asp?action=update&amp;item=<%=dispRS.Fields("Znum")%>&amp;count=', 'document.forms[0].txtCount');">Update Quantity</a></td>
               
ASKER CERTIFIED SOLUTION
Avatar of damonf
damonf

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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???
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 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.
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_value(txtCount.value, txtCount)"></td>

<td ><a HREF="javascript:goTo('./shopping.asp?action=update&amp;item=<%=trim(dispRS.Fields("Znum"))%>&amp;count=', document.forms[0].txtCount.value);">Update Quantity</a></td>

<td><a HREF="./shopping.asp?action=del&amp;item=<%= dispRS.Fields("Znum")%>">Remove Item</a></td>
</tr>    
<%    
     dispRS.MoveNext
     Loop
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_value(txtCount.value, txtCount)"></td>

<td ><a HREF="javascript:goTo('./shopping.asp?action=update&amp;item=<%=trim(dispRS.Fields("Znum"))%>&amp;count=', document.forms[0].txtCount.value);">Update Quantity</a></td>

<td><a HREF="./shopping.asp?action=del&amp;item=<%= dispRS.Fields("Znum")%>">Remove Item</a></td>
</tr>    
<%    
     dispRS.MoveNext
     Loop
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_value(txtCount.value, txtCount)"></td>

<td ><a HREF="javascript:goTo('./shopping.asp?action=update&amp;item=<%=trim(dispRS.Fields("Znum"))%>&amp;count=', document.forms[0].txtCount.value);">Update Quantity</a></td>

<td><a HREF="./shopping.asp?action=del&amp;item=<%= dispRS.Fields("Znum")%>">Remove Item</a></td>
</tr>    
<%    
     dispRS.MoveNext
     Loop
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_value(txtCount.value, txtCount)"></td>

<td ><a HREF="javascript:goTo('./shopping.asp?action=update&amp;item=<%=trim(dispRS.Fields("Znum"))%>&amp;count=', document.forms[0].txtCount.value);">Update Quantity</a></td>

<td><a HREF="./shopping.asp?action=del&amp;item=<%= dispRS.Fields("Znum")%>">Remove Item</a></td>
</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.Fields("Item")%>" id="txtCount<%=dispRS.Fields("Item")%>" type="text" size="3" maxlength="100" onfocus='this.select();' value="<%= dispRS.Fields("Quantity")%>" onchange="javascript:get_value(txtCount<%=dispRS.Fields("Item")%>.value, txtCount<%=dispRS.Fields("Item")%>)"></td>

<td ><a HREF="javascript:goTo('./shopping.asp?action=update&amp;item=<%=trim(dispRS.Fields("Znum"))%>&amp;count=', document.forms[0].txtCount<%=dispRS.Fields("Item")%>.value);">Update Quantity</a></td>

<td><a HREF="./shopping.asp?action=del&amp;item=<%= dispRS.Fields("Znum")%>">Remove 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.
I took out the onchange function, and changed <%dispRS.Fields("Item")%> to <%=trim(dispRS.Fields("Znum"))%>  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?
Just post a question "points for damonf" and I'll answer it.
done