Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2005
    Location
    Six Degrees From You
    Posts
    1,075

    Value in the query string using Javascript

    Hi Guys,

    I have been googleing all weekend for an answer to this but as yet I have not found one.

    Is there any way of getting the value of an input box in the query string?

    At the moment I am using:
    Code:
    document.write("<a href='page.htm?quantity=" + document.checkout.inputname.value + "'>Add</a>");
    But this adds the value of the input box on page load.

    I really dont want to have to use AJAX as it is only for 4 links so using AJAX as a little over the top.

    Any Ideas?

    Paul

  2. #2
    You need a dynamic method that will either change the link or go to the page when something is entered in the form field. try this:

    <form action="#" name="checkout">
    Quantity: <input type="text" name="inputname" value="" >
    </form>
    <a href="javascript: SetQuantity('page.htm?quantity='+document.checkout.inputname.value)">Add</a>

    <script language="JavaScript" type="text/javascript">
    function SetQuantity(page){
    if(document.checkout.inputname.value.length>0){
    location.href=page;}
    else{
    alert("Enter a quantity");}}
    </script>

  3. #3
    You could also try this:

    <a href="" name="QTY" onClick="this.href='page.htm?quantity='+document.checkout.inputname.value">Add</a>

    I didn't test it so I'm not sure if it works.

  4. #4
    Join Date
    Oct 2005
    Location
    Six Degrees From You
    Posts
    1,075
    Hi webwrigh,

    Many thanks for your replies. I have just tested your first answer and have found that to be perfect.

    I was almost there yesterday morning but thought I was going down the wrong route so scraped the code and started again.

    Many thanks for your help.

    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •