Click to See Complete Forum and Search --> : Checkbox Prompt
96turnerri
12-02-2003, 02:03 PM
hi all, i would like a prompt to come up if the users selects a checkbox, this is what ive got so far
<script>
var whatName=prompt("Please type in your name:","");
function doName(theName){
if ((whatName != "")&&(whatName !=null)){
document.writeln("Hello "+whatName+"!")
}else{
document.writeln("Hello! You")
}
}
</script>
<form name="quotation">
<input type="checkbox" name="Calculator" onClick="doName(whatName);"> <input type="text name="Calc">
what i wish to happen is if a user clicks on this checkbox a prompt comes up they type in something and it appears in textbox
Thanks for any suggestions or help
96
fredmv
12-02-2003, 02:05 PM
Something like this?<form action="#">
<input type="checkbox" onclick="foo.value=prompt('Enter your name:','');" />
<input type="text" name="foo" />
</form>
96turnerri
12-02-2003, 02:23 PM
thanks fredmv wokrs a treat as soon as i posted it and saw you were on i new you were gonna reply thanks, just a quicky when nothing is entered and click ok nothing is written in tb, when click cancel null is written in tb, is there a way to stop it writing null or have it say something else?
fredmv
12-02-2003, 02:25 PM
Here you go:<form action="#">
<input type="checkbox" onclick="n=prompt('Enter your name:','');foo.value=(n)?n:'Dude';" />
<input type="text" name="foo" />
</form>
96turnerri
12-02-2003, 02:30 PM
thanks, it not working now tho :( , i changed the way i was going to do it this is what i have got
<input type="checkbox" name="Calculator" onclick="Other.value='Calculator(s) Information = '+n=prompt('Please Tell Us The Purpose The Of Calculator(s), If Possible The Equation(s) or Proccesses Of It:','');Other.value=(n)?n:'Dude';">
thanks again
96
fredmv
12-02-2003, 02:33 PM
Check this example out:<form action="#">
<input type="checkbox" name="Calculator" onclick="n=prompt('Some question here:','');(n)?n:'Value if prompt is empty/null.';foo.value='Your text here: '+n;" />
<input type="text" name="foo" />
</form>
96turnerri
12-02-2003, 02:37 PM
:confused: still no joy getting there i can tell thanks sorry if i being stupid tongiht :rolleyes:
current code
<input type="checkbox" name="Calculator" onclick="n=prompt('Please Tell Us The Purpose The Of Calculator(s), If Possible The Equation(s) or Proccesses Of It:','');(n)?n:'None Entered';Other.value='Calculator Information: '+n;">
fredmv
12-02-2003, 02:43 PM
Oops. Sorry, minor typo. Slight error on my part. Here you go:<form action="#">
<input type="checkbox" name="Calculator" onclick="n=prompt('Please Tell Us The Purpose The Of Calculator(s), If Possible The Equation(s) or Proccesses Of It:','');n=(n)?n:'None Entered';Other.value='Calculator Information: '+n;">
<input type="text" name="Other" />
</form>
96turnerri
12-02-2003, 02:46 PM
thats lovely thanks mate, thought it may have been a typo, because i checked and double checked your code against mine, o well all sorted now thanks alot
fredmv
12-02-2003, 02:48 PM
You're very welcome. :D
96turnerri
12-02-2003, 02:52 PM
one of my subscribed thread was replied to about you have a look
http://forums.webdeveloper.com/showthread.php?s=&postid=117426#post117426
p.s. v v good post :cool:
fredmv
12-02-2003, 02:56 PM
Thanks to you and olerag, I appreciate it... I figured that would be a common problem so that's why I went into such detail -- it'll make it easier for future readers. :D