I want to distinguish the values entered by the user.
Users use an input form to add values.
If '#'
is the front of the value entered by the user. remove '#'
and redirect to A
other than that redirect to B
I tried to distinguish this by using charAt() but do not work
also i don't know .replace() is working
That code only goes to the current URL + /?, whatever i type.
please help me
<form>
<input id="pathID" placeholder="Search ..." +
style="height:40px; line-height:40px; padding:0 15px;">
<input onclick="return findSharp()" type="submit"
value="Search" style="background:#222;">
</form>
<script>
function findSharp(){
var stringName = document.getElementById("pathID").value;
if(stringName.charAt(0) == '#'){
findURLA()
} else {
findURLB()
}
}
function findURLA(){
var hashId = document.getElementById("pathID").value;
var hashIdReplace = hashId.replace('#','');
window.location.href =
'http://localhost:8181/activity-2/' + '?' +
'hashtag/' + hashIdReplace;
return false;
}
function findeURLB(){
window.location.href = 'http://localhost:8181/';
document.write("I AM URL B");
return false;
}
</script>