Eggzorcist Posted June 16, 2009 Share Posted June 16, 2009 I'm sorry it's very basic it's just its for a school project and I can't seem to get it to work. here my code function showUser(str) { if (str==5){ string = "Name: Harold<br>Location: Montreal, Canada" document.getElementById('txtHint').innerHTML = string; } else { alert("Wrong ID, Please try again"); } } I can't seem to find the issue. Thanks Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted June 16, 2009 Share Posted June 16, 2009 I'm sorry it's very basic it's just its for a school project and I can't seem to get it to work. here my code function showUser(str) { if (str==5){ string = "Name: Harold<br>Location: Montreal, Canada" document.getElementById('txtHint').innerHTML = string; } else { alert("Wrong ID, Please try again"); } } I can't seem to find the issue. Thanks Let me guess... your 'str' value comes from some form field or query string, right? If so, it's being treated as a string and not a number. To fix it, run it through the parseInt() function: function showUser(str) { str = parseInt(str); if(str == 5) { string = "Name: Harold<br>Location: Montreal, Canada"; document.getElementById('txtHint').innerHTML = string; } else { alert("Wrong ID, Please try again"); } } Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 16, 2009 Share Posted June 16, 2009 Nightslyr: JavaScript is like PHP in that respect. 5 == '5' would be true but 5 === '5' would not be. Quote Link to comment Share on other sites More sharing options...
Eggzorcist Posted June 16, 2009 Author Share Posted June 16, 2009 I've added that however, the command still gets passed to the else command. I know this isn't the problem but here is how the information is showing. <form> Package ID:<input name="id" id='id' type="text" size="10" maxlength="10" /> <br /> <input type='button' onclick='showUser(this.value)' value="Track"/> </form> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 16, 2009 Share Posted June 16, 2009 Well that would be why. Do you know what this.value is? It's Track, the value of the input button you're clicking. What you want is the value of the one above it. Quote Link to comment Share on other sites More sharing options...
Eggzorcist Posted June 16, 2009 Author Share Posted June 16, 2009 Yea I just relized. I had fixed that on one of the copy of this but not on the other. Thanks onclick="showUser(document.getElementById('id').value)" works Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.