set a var

M

mcnewsxp

how can i set a variable to true with a button onclick?
onclick="<%myvar=true%>" or something?

wrong group?
 
R

Rob W.

Op 8-10-2010 20:22, mcnewsxp schreef:
how can i set a variable to true with a button onclick?
onclick="<%myvar=true%>" or something?

wrong group?

alt.comp.lang.javascript, maybe?
 
P

Paul E. Schoen

Rob W. said:
Op 8-10-2010 20:22, mcnewsxp schreef:

alt.comp.lang.javascript, maybe?

They are not very kind to newbies. It can be done in JavaScript, but this
works with just HTML:

<html>
<head><title>SetTrue</title>
</head>
<body>
<input type="hidden" name="myVar" value=false>
myVar: <input type=text name=myTextBox
value="Click for myVar"
OnClick="myTextBox.value=myVar.value" ></input>
<input type="button" name="btSetTrue"
value="Set True" onClick="myVar.value=true;
myTextBox.value=myVar.value;" </input>
</body>
</html>

Paul
 
P

Paul E. Schoen

Sherm Pendley said:
That's not "just HTML" - the contents of both onClick attributes is
JavaScript code.

Well, I was going to dispute that, since I thought the <script
type=text/javascript> tags were needed, but I found that the browser warned
about "scripts or active controls" even with just the simple event handlers
in the input controls. However the script may not necessarily be JavaScript
unless the browser automatically chooses a script engine that matches the
syntax. This example may also be done using vbScript:

<input type="hidden" name="myVar" value=false>
myVar: <input type=text name=myTextBox
value="Click for myVar"
OnClick="myTextBox.value=myVar.value" />
<input type="button" name="btSetTrue"
value="Set True" onClick="btSetTrue.value = setDone() " />
<script type="text/vbscript">
Function setDone()
myVar.value=true
myTextBox.value=myVar.value
setDone = "Done"
End Function
</script>

Thanks for the clarification. I learned something.

Paul
 
J

Jonathan N. Little

Paul said:
This example may also be done using vbScript:

Not in my browser it won't. Do not use vbScript for on the web...we are
trying to rid the shackles of IE6.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top