javascript help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wish
    New Member
    • May 2007
    • 65

    javascript help

    if (confirm('Are%2 0you....'))%20w indow.location: 'index.php'
    why this code can not work?
  • Purple
    Recognized Expert Contributor
    • May 2007
    • 404

    #2
    Hi Wish,

    a very good question, I have another :)

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

    Purple

    Comment

    • wish
      New Member
      • May 2007
      • 65

      #3
      Originally posted by wish
      if (confirm('Are%2 0you....'))%20w indow.location: 'index.php'
      why this code can not work?
      my code is like this

      <script>draw_bu tton("delete"," javascript:if(c onfirm('Are%20y ou%20want%20to% delete%20?'))%2 0window.locatio n:' index.php?model id=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

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        Code:
        <?=$row['modelid']?>
        You need [PHP]$var = $_POST['modelid'];[/PHP]

        Comment

        • Purple
          Recognized Expert Contributor
          • May 2007
          • 404

          #5
          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..

          Comment

          • Purple
            Recognized Expert Contributor
            • May 2007
            • 404

            #6
            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

            Comment

            • Purple
              Recognized Expert Contributor
              • May 2007
              • 404

              #7
              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 ?

              Comment

              • code green
                Recognized Expert Top Contributor
                • Mar 2007
                • 1726

                #8
                You are sending the variable via a URL[HTML] index.php?model id=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

                Comment

                • Purple
                  Recognized Expert Contributor
                  • May 2007
                  • 404

                  #9
                  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 :)

                  Comment

                  Working...