Jump to content

Recommended Posts

Hey guys,

 

Been trying to sort this out for a couple of days now, with no prevail.

 

What i am trying to do is call a php while loop within my body onload tag, which then calls javascript function within that while loop.

 

But i cannot get it to work at all!!

 

here's what i have so far, but it is just not working:

 

<body onload="create_fields('1','bedrooms');<?php
while($bedroom_data = mysql_fetch_array($query_bed)){
echo "autofill(".$bedroom_data['room_width'].",".$bedroom_data['room_length'].",'".$bedroom_data['description']."');";
}?>
">

 

is what i am trying to here even possible? is the problem with calling the javascript functions within the php??

 

I have put an alert line in my functions to see if they are being called, and maybe a problem with the javascript, but its not that because the alerts aren't showing..

 

If anyone can help that would be great!!

 

cheers

 

Craig

hey Neil,

 

Yeah i have tried with an onClick event, and it works fine. But what i need it to so is run these commands auto when the page is loaded!

 

Or is there another event handler which uses a pageload event?

 

cheers

 

Craig

Ummm. PHP code is executed on the server when the page is requested. When a page reaches a browser, where any javascript is executed, there is no php code present (do a "view source" in your browser to confirm this fact.)

 

To get javascript in a browser to interact with php on a web server without causing a page reload would generally require you to use AJAX. If you don't mind the page reloading, you would use a links or a form to send data to php on the web server.

ok, so AJAX....don't suppose you could tell me what part of AJAX i would need to look into? or even a URL to a page which has the information on that i would need to research and look into??

 

I haven't really used AJAX much before, practicaly have 0% experience with AJAX.

 

cheers

 

Craig

Hey PFMaBiSmAd!

 

Ok, so i read up on AJAX, and did the tutorial where you have to create a suggestion box, which is cool! and i definitely want to use AJAX in the future, for form error checking? rather than going to a php page where the form is validated and returned to form page with errors stored in sessions....AJAX seems like a really useful tool..

 

However, i dont understand how i would use it in the case i need it to work?? don't suppose you can help me?

 

What i need to do is in a while loop, go through each room in my mysql fetch array and then for each, generate a room, and then put the data from my mysql into it....

 

So i have a javascript page which has the function 'GetXmlHttpObject' to create the xmlHttp object.

Then i would another method which preforms the create_fields() function and then the autofill() function to put the data in.

But this needs to be done within a php while loop, how would i get the javascript to interact with this while loop? do i need to put the while loop in a variable and then return the variable into a javascript variable?

 

I'm really confused here! any help would be great!!

 

thanks

 

Craig

I re-read your first post and read your last post and I cannot determine what you are trying to do, but the purpose of php is to output content (HTML/Javascript/CSS) to the browser. I think you are trying to use javascript to build that content in the browser instead of letting php build it on the server.

 

Can you describe what it is you are trying to accomplish.

Ok,

 

What i have is a page called 'house_upload2.php'. Which is a page which the stage 2 of a 3 stage property upload system. Where a user uploads details and then uploads images to my database using mysql.

 

What i am trying to do is create an edit property function where the user can go through all the steps again and change the property details. So what i want to do is use the same pages for my upload facility, but i have sent a variable along the url for the pages, where i use PHP to capture that variable using 'GET'. the variable is called function, and if they click to edit a property, the url would be as follows:

 

'propertyManager/house_upload2.php?function=edit'

 

So i have if statements on my pages where if the $function variable is equal to edit, then it collects the property data from my database, so when the page loads, the input fields display the data of that property that they are editing!!

 

Does that make sense??! i hope so!

 

So on house_upload2.php, i had a function using javascript which when a user selects how many bedrooms is in their property from a drop down box, it generates the input fields and description box for that many rooms.

 

So what i want to do, is if they are EDITING the property, i want to pull the number of bedrooms the property has, and then output the input boxes etc as before, but then put all the data for these rooms in those fields by taking the data from my database....

 

Obviously i tried to do this from when the page loads, i want it to do it automatically when the page is opened.

But i need to somehow loop through each bedrooms data and put it in the right boxes..

 

Does that clear up what i'm trying to do??

 

Is this a case for AJAX? or am i missing something here? do i need basic php? i tried looking for examples of what i'm trying to do but couldn't find anything.....

 

if you can provide some help that would be excellent!

 

cheers

 

Craig

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.