Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling perl from javascript

Status
Not open for further replies.

RexJacobus

Programmer
Dec 10, 2001
47
0
0
NZ
Please help. I'm trying to write a form that can overwrite some files on the server.

In the head of my HTML form:

function SendNews(f,n)
{
var decision =confirm("Are you sure you want to overwrite."))
if decision == true
{
{document.location = " alert("Sent to server");
return true;
else
alert("News not sent");
return false;
}

In the body of my HTML form:

<input type=submit value='Change News' onClick="SendNews(text1,text2)";>

But nothing happens. Neither alert fires, I get no error msgs, nothing.

thanks,
 
Your "if" syntax is missing the mandatory brackets around the test condition. You also have some extra and some missing braces.

Try formatting your code properly (indentation always helps to spot these things) and correcting the invalid syntax and see if the code works.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
No, I haven't yet. Thanks for the pointers, I am not used to javascript at all. Here is what it looks with my latest changes

In the <head>

function SendNews(f,n)
{
var decision =confirm("Are you sure you want to overwrite?");
if (decision == true)
{
document.location = " alert("Sent to server");
return true;
}
else
{
alert("News not sent");
return false;
}
}

and in the <body>

<input type=submit value='Change News' onClick="SendNews($filename,$news)">

Rex
 
If you want to pass the value of f and n instead of passing the literal strings "f" and "n", you need to break apart the string. So you'd change this:

Code:
document.location = "[URL unfurl="true"]http://localhost/cgi_bin/tlib/editnews.pl?filename=f+news=n";[/URL]

to this:

Code:
document.location = "[URL unfurl="true"]http://localhost/cgi_bin/tlib/editnews.pl?filename="[/URL] + f + "+news=" + n;

Dan




Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I have changed the line as you instructed but I still am not getting any of the alerts/ confirms. Does that mean I still have syntax errors?

<script language=/"JavaScript/">
<!--
function SendNews(f,n)
{
var decision =confirm("Are you sure you want to overwrite?");
if (decision == true)
{
document.location = " + f + "+news=" + n;
alert("Sent to server");
return true;
}
else
{
alert("News not sent");
return false;
}
}

//-->
</SCRIPT>

Rex

ps. thanks
 
Now you've shown more of the code, I can see more errors. This line should not have escaped quotes:

Code:
<script language=/"JavaScript/">

The "language" attribute is pretty much old-hat. I'd change it to read:

Code:
<script type="text/javascript">

Give that a go and see how it works.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Of course you're not getting the alert. You changed the URL of the page so the script is no longer there. If you want the alert to show, put it BEFORE you change the page location.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top