Page 1 of 1

multiple properties

PostPosted: Thu Apr 24, 2008 4:13 am
by byronyasgur
apologies if this is obvious but i cant find out how to make the selection for multiple properties work like it does on the demo site : Item to show calendar form selector - request some help ( or code ) please. not that familiar with ajax (yet) btw

Re: multiple properties

PostPosted: Thu Apr 24, 2008 8:59 am
by chris
Hi there and welcome to the forum :)

The "Item" selector, ie the select box, does not use any ajax.
It is just a simple form select list like this:
Code: Select all
<form action=calendar.php" method="get">
<select name="id_item" onchange="this.form.submit()">
               <option value="6" >Property 6</option>
               <option value="7" >Property 7</option>
               <option value="8" >Property 8</option>
               <option value="9" >Property 9</option>
            </select>
</form>

This sends the value $_REQUEST["id_item"] to the page which is used near the start of the code to define which item to show.

Chris

Re: multiple properties

PostPosted: Thu Apr 24, 2008 7:13 pm
by byronyasgur
thanks chris - i got so far with this but my javascript is pretty rusty and i am having difficulties with the form and cant find an answer - could you help

problem is the select box keeps popping back to the first on the list or the selected ( i suppose it's supposed to do this ) but on your page it maintains the selected property - so if you select property 6 then while the page displays property 6 so does the selection box -
also and probably related, i cant get the page to go back and dispaly the default selection - so when i select property 3 after 2 being default, everything is good, but i cant go back to 2 again unless i reload the page with the base url
sorry i know this is a pretty basic question but if you could just point me in the right direction i would be obliged - i am thinking it has something to do with using selectedindex but i dont know for sure

my code:


//id of item to modify - this should be your id for the hotel/apartment/etc
if(isset($_REQUEST["id_item"])) define("ID_ITEM", $_REQUEST["id_item"]); # id sent via url, form session etc
else define("ID_ITEM", 2); # default used for demo
if(isset($_REQUEST["id_item"])) define("ID_ITEM", $_REQUEST["id_item"]); # id sent via url, form session etc
else define("ID_ITEM", 3);
if(isset($_REQUEST["id_item"])) define("ID_ITEM", $_REQUEST["id_item"]); # id sent via url, form session etc
else define("ID_ITEM", 4);

<form method="get" action = "index.php">
<table cellpadding="1" cellspacing="1" width="100%" align="center">
<select name="id_item" onchange="this.form.submit()" >
<option value="2" >Property 2 </option>
<option value="3" >Property 3</option>
<option value="4" >Property 4</option>
</select>

Re: multiple properties

PostPosted: Thu Apr 24, 2008 7:45 pm
by chris
don't worry,
It isn't actually javascript either, well, just the "onchange" bit in the select field.
This is a php problem.
You are going wrong here:
Code: Select all
//id of item to modify - this should be your id for the hotel/apartment/etc
if(isset($_REQUEST["id_item"])) define("ID_ITEM", $_REQUEST["id_item"]); # id sent via url, form session etc
else define("ID_ITEM", 2); # default used for demo
if(isset($_REQUEST["id_item"])) define("ID_ITEM", $_REQUEST["id_item"]); # id sent via url, form session etc
else define("ID_ITEM", 3);
if(isset($_REQUEST["id_item"])) define("ID_ITEM", $_REQUEST["id_item"]); # id sent via url, form session etc
else define("ID_ITEM", 4);

Basically you don't need all this.
You should only need this first one as in the original:
Code: Select all
if(isset($_REQUEST["id_item"])) define("ID_ITEM", $_REQUEST["id_item"]); # id sent via url, form session etc
else define("ID_ITEM", 2); # default used for demo


To get the select box to have the selected item highlighted, modify your select list to this:
Code: Select all
<option value="2" <?php if(ID_ITEM==2) echo "selected"; ?>>Property 2 </option>
<option value="3" <?php if(ID_ITEM==3) echo "selected"; ?>>Property 3</option>
<option value="4" <?php if(ID_ITEM==4) echo "selected"; ?>>Property 4</option>


I can't quite undertand why you can't get it back to the original item with reloading the base url :(

See if by making these changes that problem goes away, if not, you know who to call ;)

Chris

Re: multiple properties

PostPosted: Thu Apr 24, 2008 7:57 pm
by byronyasgur
thanks for quick response - yes i understand that bit but it is still showing the same behaviour - both problems - it is neither showing the correct selection value on the form nor displayting what would have been the default selection once another has been chosen - i am running wampserver on a local machine - could this have anything to do with it ?

Re: multiple properties

PostPosted: Thu Apr 24, 2008 8:22 pm
by chris
I'm afraid that I have no experience with wampserver but I wouldn't have thought so, this is just basic php stuff (in theory)

Could you pm me your code for the calendar page so that I could take a look at the whole lot?

Chris

Re: multiple properties

PostPosted: Thu Apr 24, 2008 8:26 pm
by byronyasgur
sent you pm

Re: multiple properties

PostPosted: Thu Apr 24, 2008 8:34 pm
by chris
OK, first thing, I didn't realise that you had included the select list within php so you will need to change this:
Code: Select all
<option value="2" <?php if(ID_ITEM==2) echo "selected"; ?>>Property 2</option>
<option value="3" <?php if(ID_ITEM==3) echo "selected"; ?>>Property 3</option>
<option value="4" <?php if(ID_ITEM==4) echo "selected"; ?>>Property 4</option>

for this:
Code: Select all
<option value="2" '; if(ID_ITEM==2) echo "selected"; echo '>Property 2</option>
    <option value="3" '; if(ID_ITEM==3) echo "selected"; echo '>Property 3</option>
    <option value="4" '; if(ID_ITEM==4) echo "selected"; echo '>Property 4</option>


I have copied your version (which I see is basically untouched from the zip version) and, having changed that bit of code, at least in my server is now works as expected.
See if that change solves anything...

Chris

Re: multiple properties

PostPosted: Thu Apr 24, 2008 8:46 pm
by byronyasgur
thats got it - sorry i didnt realise you had index programmed that way - never saw it done before actually - but that's for another day - thanks - i am researching this for a client so if they use script i will recommend a donation from them - thanks

Re: multiple properties

PostPosted: Thu Apr 24, 2008 8:53 pm
by chris
good news!
It is debatable as to whether or not one should open and close php tags a lot through the code. Apparantly not doing so (ie like I don't :( ) can cause slightly worse performance. However, you have to balance that off with readability and ease of programming - for me that is more important (maybe because I don't have any high volume sites :) )

As I often mention throughout the forum, any donations would be most welcome ;)

Chris