jquery - Change text in text field according to link that has been clicked -
i have following.
<div class="petsearch"> <input id="pet_search_input" class="" type="text" onkeypress="return isnumberkey(event)" name="query" autocomplete="off"> </div>
now if user types dog in text field below link looks following.
<a id="pets" href="#dog" onclick="main()"> <img title="dog" alt="dog" src="./images/dog.png"> </a>
now if user types cat link appears looks following.
<a id="pets" href="#cat" onclick="main()"> <img title="cat" alt="cat" src="./images/cat.png"> </a>
so have jquery looks following.
$("#pets").click(function () { $("#hidden_content").hide("fast"); $("#yourpet").hide("fast"); $("#pet_search_input").hide("fast"); });
now have following on same page next each image text field appear follows.
<input type="text" id="pet-type">
the above input put have word appear value when user clicks on link. if link #cat input value feline when link clicked. if link has #dog input value of mut when user clicks link has #dog.
my goal have above input type text display name of animal when user click link. if user clicks link , link says dog input update dog. don't know how achieve this. worth noting #dog can ?dog or &dog. can please me achieve this.
update @alvin giving code means i'm getting closer i'm trying achieve.
$("#pets").click(function () { $("#hidden_content").hide("fast"); $("#yourpet").hide("fast"); $("#pet_search_input").hide("fast"); var result = $("#pets").attr("href"); result = result.replace("#",""); $("#pet-type").attr("value",result); });
but think if should following.
$("#pets").click(function () { $("#hidden_content").hide("fast"); $("#yourpet").hide("fast"); $("#pet_search_input").hide("fast"); if $("#pets").attr("href","#cat") $("pet-type".attr("value","feline"); else if if $("#pets").attr("href","#dog") $("pet-type".attr("value","mut"); });
the above code doesn't work think people should see i'm trying accomplish.
update i've tried following.
if $("#pets".attr("href","#cat"),$("#pet-type").attr("value","feline"); if $("#pets".attr("href","#dog"),$("#pet-type").attr("value","mut");
solved closed
change javascript to
$("#pets").click(function () { $("#hidden_content").hide("fast"); $("#yourpet").hide("fast"); $("#pet_search_input").hide("fast"); var result = $("#pets").attr("href"); if (result == "#cat"){ $("#pet-type").attr("value","feline"); } if (result == "#dog"){ $("#pet-type").attr("value","mut"); } });
hope helps.
Comments
Post a Comment