Results 1 to 6 of 6

Thread: go to a url entered in a certain textbox

  1. #1
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default go to a url entered in a certain textbox

    Okay i need to make it so that the text area "place" can have a url entered into it, and then after it is entered and submitted it will set $line to go to the url entered.

    Code:
    <form action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST" name="todo">
    <input type="hidden" name="ohash" value="<?php echo $hash ?>" />
    <pre>
    <?php
    
        $data = file ( $file );
        $n = 0;
    
        foreach ( $data as $line ) { 
    
            echo "<input type='checkbox' name='line[$n]' />";
            echo $line ;
    
            $n++;
    
        }
    
    ?>
    </pre>
    <hr />
    <input type="text" name="place" size="35" />
    <input type="text" name="data" size="35" />
    <input type="submit" name="submit" value="Add" />
    <input type="submit" name="submit" value="Remove" /> 
    </form>

  2. #2
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Pretty simple:

    Code:
    //After form has been submited
    <?Php header("location:".$_POST['place']); ?>
    d-one

  3. #3
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    so do i put that right after the submit button or in the script?

  4. #4
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    oh no i mean when you click on the text in $line, it goes, not when the page is submitted.

  5. #5
    Join Date
    Nov 2006
    Location
    UK
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    if that is the case, your in the wrong place, PHP can only do this on the server side, you probably want to use javascript to do this

    Insert in the head of the page:

    Code:
    <script language="javascript" type="text/javascript">
    function gothere(){
       if (document.todo.place.value != ""){
          document.location.href=document.todo.place.value;
       }
       else{
          alert("please enter a location!");
       }
       return false;
    }
    </script>
    Then in the <form> tag, place this somewhere

    Code:
    onSubmit="gothere()"
    or do you want the page to reload with the link on the page?

    if that is the case, use javascript again...

    Code:
    <script language="javascript" type="text/javascript">
    function gothere(){
       if (document.todo.place.value != ""){
          document.golink.innerHTML="<a href="+document.todo.place.value+">"+document.todo.place.value+"</a>";
       }
       else{
          alert("please enter a location!");
       }
       return false;
    }
    </script>
    and have this DIV on the page where you want the link to appear...

    Code:
    <div name="todo" id="todo"></div>
    hope that this helps somewhat...
    Last edited by GITs; 11-10-2006 at 03:03 PM.

  6. #6
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    well i got part now, but still one problem...
    Code:
    <form action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST" name="todo">
    <input type="hidden" name="ohash" value="<?php echo $hash ?>" />
    <pre>
    <input type="text" name="place" size="35" />
    <input type="text" name="data" size="35" />
    <input type="submit" name="submit" value="Add" />
    <input type="submit" name="submit" value="Remove" />
    <?php
    
        $data = file ( $file );
        $n = 0;
    
        foreach ( $data as $line ) {
    
            echo "<input type='checkbox' name='line[$n]' />" ;
    		echo "<a href=$place>$line</a>" ;
    
            $n++;
    
    	
        }
    
    ?>
    </pre>
    Now is there any way to make it so that even with the fields on top, the data appears above it?

    It works right now but makes the fields at the top and I want them switched but the input "place" needs to stay at the top so it can retrieve the field's data in the href...


    if that makes any sense.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •