0

My Question : A value which is passed by an id is showing in the input box. but i can not see that value in the html source code section.

This is my input field In which i am passing a value through a cookie.

<input type="text" id="city" class="i-p-c" value="" autocomplete="off" placeholder="Select City">

What i am doing is: I have a drop down of cities. when i click on the city. i am setting a cookie with the name of scity.

$("#cuto li").click(function () {
    autoValuenew = this.id; // console.log(autoValuenew);
    document.cookie = "scity=" + this.id + ";path=/;domain=" + cookieondomain;

   document.getElementById('city').value = this.id; 
   //Here is am pass a value to city 

return false;
});

After that .. I can access the value of city but i can not see that value in the html source code.

When i change my field type text to hidden type i can see the value in the htmlsource code.

I do not understand what is going here with these two types. or if i am doing something please tell where i am doing wrong. or if there is another way to do this.

Vishal Kumar
  • 262
  • 1
  • 5
  • 18

2 Answers2

3

Kindly look this code I hope it helps

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>

<input type="text" id="city" class="i-p-c" value="" autocomplete="off" placeholder="Select City"/>
<ul id="cuto">
<li type="button" id="cuto">test</li>
</ul>

here is your JQuery

$("#cuto li").click(function () {
debugger;
    autoValuenew = this.id; // console.log(autoValuenew);
    $.cookie("scity", "test value"); // Setting cookie value
    //document.cookie = "scity=" + this.id + ";path=/;domain=" + cookieondomain;

   document.getElementById('city').value = this.id; 
   //Here is am pass a value to city 

return false;
});
M.Nabeel
  • 1,066
  • 7
  • 19
2

element.setAttribute('value', myValue);


I think you should not just change the value change it in by changing attribute value.
Nambi N Rajan
  • 491
  • 5
  • 15