2

I want to pass two variables to my .php page ... the drop down variable is working great. But when I added an additional variable, it only sends a 0 instead of what I enter in the form.

I feel like I'm fairly close to the solution on this ... when I substitute a number on this line:

    xmlhttp.open("GET","getdeposit.php?q="+str + "&r=" +restaurant, true);

instead of +restaurant, I use + 101 ... then this page correctly passes 101 ... but when I just enter the number in my form, it returns 0

<html>
<head>


<script>
function showUser(str) {
if (str == "") {
    document.getElementById("txtHint").innerHTML = "";
    return;
} else { 
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else {
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","getdeposit.php?q="+str + "&r=" +restaurant, true);
    xmlhttp.send();
}
}
</script>

</head>
<body>

<form>
<p>
 <label for="restaurant">Restaurant:</label>            
 <input type="text" id="restaurant" name="restaurant" placeholder="Enter    Restaurant" />
</p>
<select name="users" onchange="showUser(this.value)">
  <option value="">select a date</optoin>
  <option value=" ">Today</option>
  <option value="1">Yesterday</option>
  <option value="2">Two Days Ago</option>
  </select>
</form>

<div id="txtHint"><b>Select Business Date</b></div>

</body>
</html>
1
  • Did you set the variable restaurant in your showUser function? I can't see it, maybe that's the problem. Commented Feb 10, 2015 at 19:20

1 Answer 1

2

Add the following just above the if statement in your js function :

        var restaurant = document.getElementById('restaurant').value;
Sign up to request clarification or add additional context in comments.

1 Comment

@DeFirmo I added it above the first IF in the js function and it worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.