By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

javascript help

P: 65
if (confirm('Are%20you....'))%20window.location:'inde x.php'
why this code can not work?
May 11 '07 #1
Share this Question
Share on Google+
8 Replies


Purple
Expert 100+
P: 404
Hi Wish,

a very good question, I have another :)

can you post a little more so we can see what you are doing..

Purple
May 11 '07 #2

P: 65
if (confirm('Are%20you....'))%20window.location:'inde x.php'
why this code can not work?
my code is like this

<script>draw_button("delete","javascript:if(confir m('Are%20you%20want%20to%delete%20?'))%20window.lo cation:' index.php?modelid=1' ","","","","")</script>

if can modelid is refer to database model id...so i may use php script <?=$row['modelid']?>

but this code can not work
May 11 '07 #3

code green
Expert 100+
P: 1,726
Expand|Select|Wrap|Line Numbers
  1. <?=$row['modelid']?>
You need [PHP]$var = $_POST['modelid'];[/PHP]
May 11 '07 #4

Purple
Expert 100+
P: 404
Hi,

I think I am begining to understand a little better now.. If you are trying to use the value of $row['modelid'], change

[PHP]<?=$row['modelid']?>[/PHP]

to

[PHP]<?php echo $row['modelid']?> [/PHP]

if the javascript header redirect isn't happening, post again..
May 11 '07 #5

Purple
Expert 100+
P: 404
Hi,

can you also wrap the code in tags to make it easier to read - I was totally confused looking at your first post. But then thats not too difficult :)

Purple
May 11 '07 #6

Purple
Expert 100+
P: 404
Hi Wish,

have done a little more on this and again more questions - if you are still having issues with the redirect try this javascript code:

[PHP]function confirm_but()
{
if (confirm('Are you sure'))
{
alert('running redirect');
window.location='http://your/target/dir/file.php';
alert('after redirect');
}
}[/PHP]

fire with an onclick on the submit - if it fixes the problem great, if not, watch the bottom address bar as the 2nd alert is run.. is that showing the correct url for the redirect ?
May 11 '07 #7

code green
Expert 100+
P: 1,726
You are sending the variable via a URL[HTML] index.php?modelid=1' [/HTML] If you want to read this in index.php you need [PHP]$var = $_GET['modelid'];[/PHP]
Then [PHP]echo $var;[/PHP] should print 1
May 11 '07 #8

Purple
Expert 100+
P: 404
Hi Code Green - I am not convinced that is his problem

I have recreated and the redirect appears not to work - I think he has the form set to refresh itself on submit so the javascript redirect is being followed by the form refresh

Try the javascript function I posted and it ilustrates the problem better - I obviously caveat that with I have only tried it on IE7 :)
May 11 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.