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.

5
  • What do you mean by can not see that value in the html element section? Commented Jul 20, 2017 at 9:43
  • in my source code @H77 Commented Jul 20, 2017 at 9:47
  • 1
    Check stackoverflow.com/questions/31322704/… Commented Jul 20, 2017 at 9:48
  • do you get any errors in console window? Commented Jul 20, 2017 at 9:49
  • No.. i did not get @M.Nabeel Commented Jul 20, 2017 at 9:51

2 Answers 2

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;
});
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you @M.Nabeel
Happy to be help Vishal. If it helps please marked it as answer :)
But what i needed is @Pratheesh Answer
2

element.setAttribute('value', myValue);


I think you should not just change the value change it in by changing attribute value.

Comments

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.