Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Open page in selected div

    Thanks in advance for any help.

    In a nutshell, my problem is that I can't work out how to open a selected page (lets call it confirm.html) in a selected DIV (lets call it 'CONTENT') after I submit a form.

    Forgetting the form for a second, when my main page loads, there are two DIVS
    1. 'CONTENT'
    2. 'MENU'

    The following function calls the selected pages into these divs when the main page loads:

    <script type="text/javascript">
    ajaxpage1('farm.html', 'content')
    ajaxpage1('login.html', 'menu')
    </script>

    When you click on the "registration" link on login.html in the menu div, the following function on the login.html page opens registration.html in the content div:

    <a href="javascript:ajaxpage1('register.html','content');" class="nav">

    Now a form comes up. But when i submit the form, which sends the data to registration.php, I can't get the next page ("confirm.html") to open in the content div.

    I have tried the following in the registration.php page without luck:

    echo "<script language=javascript>document.location.href=ajaxpage1('confirm.html', 'content')</script>";

    Does anyone know how far off I am. If you help me I will buy you a case of beer. cheers.

  • #2
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    367
    Thanks
    9
    Thanked 53 Times in 52 Posts
    Shouldn't it be just echo "<script type='text/javascript'>ajaxpage1('confirm.html', 'content')</script>"; ?

    The "language=javascript" is dropped since it's quite obsolete I gues , and "document.location.href=" is too since it would redirect the whole page.

    Tell me the result then, good luck...

  • #3
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    that must be close,

    there was no error message, but the content div just came back as a blank page. no new window opened and the whole page didnt refresh?

  • #4
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    367
    Thanks
    9
    Thanked 53 Times in 52 Posts
    Hmm..
    I thought registration.php was at the end just redirecting "content" div to confirm.html. Would be helpful if you provide what's inside registration.php, is it transferring some parameters to the confirm.html?

    "no new window opened and the whole page didnt refresh?"
    I have idea what and which is responsible for opening new window or page refresh. Please be more details...
    Last edited by hdewantara; 11-29-2009 at 04:53 AM.

  • #5
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    "no new window opened and the whole page didnt refresh?"

    disregard this....check out my website, it may be more helpful.....www.downunderfarmers.com. See the registration button on the right. Thats where it all starts.

    OK here are the contents of registration.php:


    Code:
    <?PHP
    
    $user_name="xxx";
    $password="xxx";
    $database="xxx";
    $server="xxx";
    
    mysql_connect($server, $user_name, $password)or die("Could not connect: ".mysql_error());
    mysql_select_db($database) or die(mysql_error());
    
    
    $prefix = $_POST['prefix'];
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $number = $_POST['number'];
    $type = $_POST['type'];
    $email = $_POST['email'];
    $street= $_POST['street'];
    $suburb = $_POST['suburb'];
    $postcode = $_POST['postcode'];
    $city = $_POST['city'];
    $username = $_POST['username'];
    $password1 = $_POST['password'];
    $password2= $_POST['password1'];
    
    
    $query = "INSERT INTO users (prefix, firstname, lastname,
     number, type, email, street, suburb, postcode, city, 
    username, password, password1)
    VALUES
    ('$prefix', '$firstname', '$lastname', '$number', '$type', 
    '$email', '$street', '$suburb', '$postcode', '$city', 
    '$username', '$password1', '$password2')";
    
    mysql_query($query) or die(mysql_error());
    
    
    echo "<script type='text/javascript'>ajaxpage1('confirm.html', 'content')</script>";
                
     
    mysql_close();
    
    ?>

    cheers

    Also, this is the ajax function itself. Maybe theres a problem within it.


    Code:
    <script type="text/javascript">
    
    var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
    var loadedobjects=""
    var rootdomain="http://"+window.location.hostname
    var bustcacheparameter=""
    
    function ajaxpage1(url, containerid){
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // if IE
    try {
    page_request = new ActiveXObject("Msxml2.XMLHTTP")
    } 
    catch (e){
    try{
    page_request = new ActiveXObject("Microsoft.XMLHTTP")
    }
    catch (e){}
    }
    }
    else
    return false
    page_request.onreadystatechange=function(){
    loadpage(page_request, containerid)
    }
    if (bustcachevar) //if bust caching of external page
    bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
    page_request.open('GET', url+bustcacheparameter, true)
    page_request.send(null)
    }
    
    function loadpage(page_request, containerid){
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
    document.getElementById(containerid).innerHTML=page_request.responseText
    }
    
    function loadobjs(){
    if (!document.getElementById)
    return
    for (i=0; i<arguments.length; i++){
    var file=arguments[i]
    var fileref=""
    if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
    if (file.indexOf(".js")!=-1){ //If object is a js file
    fileref=document.createElement('script')
    fileref.setAttribute("type","text/javascript");
    fileref.setAttribute("src", file);
    }
    else if (file.indexOf(".css")!=-1){ //If object is a css file
    fileref=document.createElement("link")
    fileref.setAttribute("rel", "stylesheet");
    fileref.setAttribute("type", "text/css");
    fileref.setAttribute("href", file);
    }
    }
    if (fileref!=""){
    document.getElementsByTagName("head").item(0).appendChild(fileref)
    loadedobjects+=file+" " //Remember this object as being already added to page
    }
    }
    }
    
    </script>
    Last edited by drob2689; 11-29-2009 at 05:22 AM.

  • #6
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    367
    Thanks
    9
    Thanked 53 Times in 52 Posts
    See the registration.php, try enclose the
    ...<script type='text/javascript'>ajaxpage1('confirm.html', 'content')</script>...
    so it'll become:
    ...<html><body><script type='text/javascript'>ajaxpage1('confirm.html', 'content')</script></html></body>...

    Additional note: your ajax script seems ok, though not well written. You might refine it by adding some ";".

  • #7
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    OK

    I tried everything and nothing worked. So I tried something else which fixed it but caused another problem which may be easier to fix I hope.

    on the registration.html page, the one holding the form, i changed the action from

    action=registration.php
    to
    action="javascript:ajaxpage1('registration.php','content');"

    then in the registration.php I simply put

    header("Location:confirm.html");

    Now confirm.html opens in the correct DIV, and there is a new line in the database....BUT ALL THE FIELDS ARE BLANK IN IT.

  • #8
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    367
    Thanks
    9
    Thanked 53 Times in 52 Posts
    I experimented a bit with your scripts in my free server,
    and edited them as follows:

    1) ajaxpage1() now re-declared as ajaxpage1(url,method,containerid),
    to handle either GET/POST form methods. While no change applied to GET method,
    POST method is added to handle 2 form inputs (yours is more than 2) in register.htm,
    each inputs must be name-ed and id-ed:
    ...
    if (method=="POST"){
    page_request.open('POST', url, true);
    var
    params="username=";
    params+=document.getElementById("username").value;
    params+="&useraddr=";
    params+=document.getElementById("useraddr").value;

    page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    page_request.setRequestHeader("Content-length", params.length);
    page_request.setRequestHeader("Connection", "close");

    page_request.send(params);
    }
    else
    if (method=="GET"){
    page_request.open('GET', url, true);
    page_request.send(null);
    }
    ...

    2) whoever wants to load register.html into 'content' shall use: javascript:ajaxpage1('register.html','GET','content');

    3) register.htm was changed to someting like:
    <form action="javascript:ajaxpage1('registration.php','POST','content');">
    <br />Your name: <input type="text" id="username" name="username" />
    <br />Your address: <input type="text" id="useraddr" name="useraddr" />
    <br /><input type="submit" value="submit" />
    </form>

    4) I used header("Location:confirm.html"); as last line of registration.php as you've suggested and got this
    ...Warning: Cannot modify header information - headers already sent by (output started at /home/freehost/t35.com/e/g/eggsofbali/registration.php:3) in /home/freehost/t35.com/e/g/eggsofbali/registration.php on line 11...

    Well, I think it was probably caused by my "free" server .

  • Users who have thanked hdewantara for this post:

    drob2689 (11-30-2009)

  • #9
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks for your help but i still cant get it, what is your email adress. if you want to try on my server, ill send u my login details. there is nothing there that is private yet anyway so i dont mind.


  •  

    Posting Permissions

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