<input type=button value='Do Stuff' onClick='document.cookie = "Note_<% Response.Write(arrTest(0,i)) %> = ' + (Document.getElementById("StuffTest<% Response.Write(arrTest(0,i)) %>").value) + '"'>
What I’m trying to do here is when the user hits the button, I want a cookie created with the values: Note_(value of arrTest) = (Value of the text box).
The code below works just fine:
<input type=button value='Do Stuff' onClick='document.cookie = "Note_<% Response.Write(arrTest(0,i)) %> = Awesome!"'>
It creates a cookie with the value of: Note_(value of arrTest) = Awesome!
What have I done wrong to get the value of my text box into the cookie? I’m assuming it has to do with all those confusing single/double quotes, so I think I’ve just got typo-blindness, but part of me thinks I can’t actually do what I’m trying to do here.
Any thoughts?
document.getElementByIdhasdocumentin all lower case. Your code example usesDocument(with a capitalD), which will fail.Separately, your quotes such in the
onClickattribute are not quite right. It’s best to avoid putting any significant code in those attributes. Instead, define and call a function, like this:…where the function (inside a
<script>tag or in a file referenced by one) looks like this:Depending on the contents of
arrTest(0,i), you might need to HTML-encode it as you output it, since you’re outputting it to HTML (yes, the code inside anonXYZattribute is HTML, just like any other attribute’s value, so for instance<would need to be<).