www.webdeveloper.com
Results 1 to 5 of 5

Thread: Value of checkbox in $_POST Url

  1. #1
    Join Date
    May 2009
    Posts
    6

    Question Value of checkbox in $_POST Url

    Dear all,

    I need help...

    I'm developing a site where the user can zoom in on a google map to find out more about a certain location and experiences that other users have uploaded. (http://www.g8journey.com/destination...tions_main.php)

    You can view a working version of the map, although without a working solution for the checkboxes at: http://www.g8journey.com/destination...ions_main2.php

    The users have uploaded different types of experiences, such as Sun & Beach, City, Cruise...etc... I would now like to add functionality so the user can choose which types of experiences that they would like to see on the map. This is done via checkboxes. The user click the checkboxes for city and cruise and the hits the submit-button.

    The function below calls the phpsqlajax_genxml2.php-file which holds the actual SQL-statement for the selection for which pictures to display. I would like to send the parametres of which checkboxes that have been selectec to the phpsqlajax_genxml2.php-file and then include the parametres into the Select-statement to select wished pictures.


    Code:
          function initialize() {
            	if(GBrowserIsCompatible()) {
              map = new GMap2(document.getElementById('map'));
              map.setCenter(new GLatLng(30.178868, 116.38), 1);
              map.addControl(new GLargeMapControl());
              var icon = new GIcon(G_DEFAULT_ICON);
              icon.image = "http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png";
              GDownloadUrl("phpsqlajax_genxml2.php?sunbeach="+document.showtype.sunbeach.value[0].checked"&bogus="+(new Date()).getTime(),processMyData); //Calls the xml-data and sends it to processMYyData-function
            }
           
          }
    I've added:

    Code:
    sunbeach="+document.showtype.sunbeach.value[0].checked
    And I had hoped that this line should include the value of the checkbox but I only get javascript-errors and I can not figur out what's wrong.

    The actual form:

    Code:
    echo '<form id="showtype" action="'.$_SERVER['PHP_SELF'].'" method="post" enctype="multipart/form-data">
    	<input type="checkbox" style="cursor:hand" name="sunbeach" id="sunbeach" value="sunbeach"/>
    <label for="var">Sun & Beach</label><br />	
    <input class="submit" type="submit" name="showtype" value="Show Type" />
    	</form>';
    Any help and suggestions are welcome!

    Thank you,

    Nimrod

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    sunbeachValue gives "sunbeach"
    sunbeachState gives "true" or "false" depending on it's state
    Code:
    var sunbeachValue=document.showtype.sunbeach.value;
    var sunbeachState=document.showtype.sunbeach.checked;
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    May 2009
    Posts
    6

    Question

    Thank you for the input, very much appriciated!

    I updated the script and I'm halfway to succeed with the funcktionlity but there is something that not is working as it should...

    When opening the http://www.g8journey.com/destination...tions_main.php page the script automatically selects photos with attirbute Sun & Beach without me clicking the checkbox. Why is that?
    The checkbox is unchecked so the script should show all photos.

    Client-side script:

    Code:
            	if(GBrowserIsCompatible()) {
              map = new GMap2(document.getElementById('map'));
              map.setCenter(new GLatLng(30.178868, 116.38), 1);
              map.addControl(new GLargeMapControl());
              var icon = new GIcon(G_DEFAULT_ICON);
             	var sunbeachValue;
             sunbeachValue	= document.getElementById("sunbeach").checked;
             if(document.getElementById("sunbeach").checked) 
             	{//checked
             		sunbeachValue = true;
             	} 
             	else 
             		{  //not checked
             			sunbeachValue = false;
             		}
              icon.image = "http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png";
              GDownloadUrl("phpsqlajax_genxml2.php?sunbeach=" + sunbeachValue +"&bogus="+(new Date()).getTime(),processMyData); //Calls the xml-data and sends it to processMYyData-function
            }
          }
    And the form:

    Code:
    echo '<form id="showtype" action="'.$_SERVER['PHP_SELF'].'" method="post" enctype="multipart/form-data">
    	<input type="checkbox" style="cursor:hand" name="sunbeach" id="sunbeach" value="sunbeach"/>
    <label for="var">Sun & Beach</label><br />	
    <input class="submit" type="submit" name="showtype" value="Show Type" />
    	</form>';
    Serverside script:

    Code:
    	$sunbeachstatus = $_REQUEST['sunbeach'];
    	IF ($sunbeachstatus == true){
    	$query = "SELECT * FROM plogger_pictures WHERE type_of_exp='1'";
    }
    ELSE
    {
    	$query = "SELECT * FROM plogger_pictures";
    }
    All help is so appriciated!

    Thank you,

    /Nimrod

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Quote Originally Posted by nimrod_767 View Post
    When opening the http://www.g8journey.com/destination...tions_main.php page the script automatically selects photos with attirbute Sun & Beach without me clicking the checkbox. Why is that?
    I see no photos
    Quote Originally Posted by nimrod_767 View Post
    The checkbox is unchecked so the script should show all photos.
    Are there relevant photos in the DB? How are these photos displayed?

    No need for the if...else after this line. They both do the same thing.
    Code:
    sunbeachValue = document.getElementById("sunbeach").checked;
    At least 98% of internet users' DNA is identical to that of chimpanzees

  5. #5
    Join Date
    May 2009
    Posts
    6

    Question

    Yes, there are relevant photos in the DB and you should see one blue circle over nothern Europe on the map saying "2" and one blue circle over the caribbean saying "6". Click on those to zoom in to the marker it iself. Then you should be able to view the photos.

    You can also compare to http://www.g8journey.com/destination...ions_main2.php where all photos in the DB are displayed.

    Ok, I'll remove the if-statement. Any other ideas of why it is not working?

    Thank you,

    /Nimrod

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles