简体   繁体   中英

Textbox is not taking the value that I assign

I have a page with 10 inputs (TextBox). I set each input value in the Page_Load with

txtColor.Text = "#FFFFFF"

Each input is a color picker. When the user pick a color, the hexa-name is set in the textbox with a javascript piece of code:

document.getElementById(txtColor).setAttribute("value", newColor);

Buuuuuuut when I try to save the changes I DONT KNOW WHY but the values saved are the old ones.

If at first the value was "FFFFFF" but then the user chose "000000" the program ignores that and save the "FFFFFF" in my db.

I'm working with vb.net

I appreciate any kind of help!

Edit: Oh god, of course it was the thing that Tim Medora say. I put the 'Not IsPostBack' and everything works just fine.

Thanks a lot, i wasnt able to see my error.

You say you're using vb script, but your post is tagged javascript. It's not clear what you're working with, but in JavaScript I'd do this:

colorPicker = document.getElementById("color-picker");
colorPicker.addEventListener("change", function () { updateTextBox(); });
textBox = document.getElementById("text-box");
function updateTextBox() {
    textBox.value = colorPicker.value;
}

Hope this helps...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM