...

View Full Version : javascript prompt



graziano
11-09-2004, 12:38 PM
Hello

I am using this





<script language="JavaScript">


function confirm_prompt(text) {
if (confirm(text)) {

}
}
</script>




on <head> section plus this



..
..
<input type="submit" value=" CONTINUE " name="continue" onclick="confirm_prompt('do you agree?'); return false;" value="" >
..
..


to show an alert when someone click on CONTINUE BUTTON .

the problem is ... I have also 2 radio modules



..
..
<INPUT TYPE="radio" VALUE="no" NAME="transfer" checked>
<INPUT TYPE="radio" VALUE="yes" NAME="transfer">
..
..


..and I wish to show the alert above ONLY if transfer (radio) value is yes and checked. Is it possible ? How to modify my script above to do that ?


Thank you
Graziano

Kor
11-09-2004, 12:59 PM
Use onsubmit, not onclick as validator event handler.
Try this:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script language="JavaScript" type="text/JavaScript">
function confirm_prompt(myform,text) {
if(myform.transfer[1].checked){
if (!confirm(text)) {
return false
}
}
}
</script>
</head>
<body>
<form onsubmit="return confirm_prompt(this,'do you agree?')">
<INPUT TYPE="radio" VALUE="no" NAME="transfer" checked>NO<br>
<INPUT TYPE="radio" VALUE="yes" NAME="transfer">YES<br>
<input type="submit" name="continue" value="Continue" >
</form>
</body>
</html>

graziano
11-09-2004, 05:08 PM
Hello Kor ,

thank you but it doesn't work (nothing happens when I click on continue button) , and as it seems it checks for ".checked" when I need to check if transfer value is "yes".

p.s. my wife is of Craiova :)

graziano
11-10-2004, 09:00 AM
anyone can help please ? Thank you

Kor
11-10-2004, 09:57 AM
It works. When click on continue
- if No is checked the form is submitted with no confirm
- if Yes is checked the confirm opens. If OK, the form is submitted, if Cancel, the submit is stoped.

Isn't it what you wanted?

graziano
11-10-2004, 10:12 AM
strange for me it didn't work . However I solved in this way



<html>
<head>
<title>Transfer or Register</title>
</head>

<body>

<script>
<!--

function ownercheck(bValue)
{
var _textForDisplay;

_textForDisplay = "You have selected to transfer a domain name." +
"To confirm that you are the legal owner of this domain name " +
"please click OK. If you are not the legal owner, " +
"please click Cancel and search for a new domain.";

if(bValue)
{
if(document.formtransfer.domainSearchTransferOption.checked)
{
var _answer = window.confirm(_textForDisplay);
if(_answer)
document.formtransfer.submit();
else
return;
window.location = 'http://www.notransfer.com';
}
else
{
document.formtransfer.submit();
}
}
else
document.formtransfer.submit();
}
//-->
</script>

<form action="http://www.yestransfer.com" ID="formtransfer" name="formtransfer">

<input type="radio" name="transfer" value="true" ID="transfer" checked>
<strong>New Domain Name</strong> <br>
<input type="radio" name="transfer" value="false" ID="domainSearchTransferOption">
<strong>Transfer an Existing Domain Name<br>
</strong>&nbsp;<input type="submit" value="Invia" name="B1" onclick="JavaScript:ownercheck(true); return false;" >


</form>
</body>
</html>

Kor
11-10-2004, 11:04 AM
Probably you have not added the action in form, in my example. Your code is somehow the same, but it is more intricate, as you have chosen to return false the submit button action, than submit with a submit() javascript method, while I just called for a return directly in form. In rest, should work the same.

----
If your wife is Romanian... have't you lear some Romanian till now? :)

graziano
11-10-2004, 12:42 PM
ops sorry , I copied an pasted your code but it didn't work because
I didn't put an action on <form> , sorry !

We married only on june I am still learning .
We are leaving in Italy so we speak always italian.
However I am learning romanian too , it's doesn't seem so hard
because it comes from latin such as italian .
One day I will travel to craiova and I will hope to learn it better .

Thank you again!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum