Jump to content

jimfog

Members
  • Posts

    1,803
  • Joined

  • Last visited

Posts posted by jimfog

  1. I am going to need a slight variation of the code-no need to open a separate topic for it.SO far we were getting the label upon the change event(meaning the user selects a different button)...but what if wanted to get the label of the currently selected radio button. I do not think the code will be much different...but I am stuck in what do exactly I have to add.

  2. Have a line of PHP inside the markup for each radio button to check the radio button's value against the value from the database. If it matches then print the attribute to select the button.
    That is what I thought to.
  3. I have made a form where some radio buttons are contained.The selection made by the user is stored in the db tables as a number, corresponding to the different values of each of the radio buttons. Here are the radio buttons with corresponding values:

    <td><input type="radio" class="formBuzType" name="buztype" value="1" > <label>test1</label><br></td>					  <td> <input type="radio" class="formBuzType" name="buztype" value="3"> <label>test3</label> <br></td>					  <td> <input type="radio" class="formBuzType"  name="buztype" value="4"> <label>test4</label>  <br></td>					  <td><input type="radio" class="formBuzType" name="buztype" value="5"> <label>test5</label> <br></td>					  <td><input type="radio"  class="formBuzType"    name="buztype" value="2"><label>test2</label> <br></td>					  

    If the user has chosen test3 then "3" will be stored in the database. Getting the value 3 from the db is not difficult(a simple SELECT query)...what I cannot do is making the appropriate preselection in the form depending on the fetched from the db value. To say it simpler...since 3 is in the db, I want when the radio buttons appear to the user(HTML) the value 3 option is selected so that the user can know what he has chosen the last time...how I will do that?

  4. I am trying to get the html content of a radio button using the .html jQuery method...actually I am trying to get the html content when the user selected a different radio button(change event). Here is the html:

    <input type="radio" class="formBuzType" name="buztype" value="1" checked>hair salon<br></td>					  <td> <input type="radio" class="formBuzType" name="buztype" value="3"> car shop <br></td>

    I am just trying to get the strings hair salon and car shop every time the user makes the corresponding selection and I am trying to achieve this with the following js code:

      $(function()   {$('.formBuzType').change(function()    { var html=$(this).html()    alert(html);	  });	 });

    I am using alert for testing purposes to see if the code will work...the result is that alert box is empty...meaning the code does not do what is supposed to be doing.Normally, whenever the user select a radio button the alert box should have in it "hair salon" or "car shop"-depending on what the user selected. What could be wrong?

  5. I tried the code below...according to the logic you described but with no results:

      $(function (){			    $('.formBuzType').change(function()			    {			    var btype = $(this).val();			    return btype;	   			    }			    );			    });      var btype;

    And regarding the error console...I tried console.log('btype'); and just got undefined. The ajax function is left unchanged.

  6. I have created a variable inside a function where it takes the value of the radio button in a form-chosen by the user...nothing strange till now.

      $(function john(){		$('.formBuzType').change(function()		{		var btype = $(this).val();		return btype;			}		);		});  

    I am talking about btype.The problem appears when I want to use the variable in ajax and send its value to a php script-from where it is inserted to a table...the variable seems to be empty, nothing is inserted to the db...here is the jquery ajax function:

    $(function() {	$('.error').hide();	 $("#savepersonal").click(function() {		event.preventDefault();		 $('.error').hide();    $.ajax({	  type: "POST",	  url: "testajax.php",	  data: {"name":name,"lastname":lastname,"btype":btype}	 });		return false;  	  	});    });

    If a put "btype":2...everything works ok 2 and gets passed to the db table.Name and lastname gets passed without problem to the db table. regarding btype, there must be a problem with the scope...but what. And another thing...is there in js an analog of var_dump found in php?

  7. but I have 1 more quesion...not related to this topic...but I am not going to open a new one since probably you are going to answer anywaysince you know js very good. I have a form with 2 radio buttons, and each is associated with a different value.I want every time the user checks a radio button(onchange event) the corresponding value is "submitted". Doing this with PHP is easy but I want to write js code so that ajax can do it.What I have managed so far is that by selecting either buttons the same value is "grabbed"...i mean the one radio button has value 5 and the other 4 but always 5 is "gets " grabbed...here is the code...HTML and js:

    <form action="" method="post">  <input type="radio" class="formBuzType" name="buztype" value="5"> salon spa <br>  <input type="radio" class="formBuzType" name="buztype" value="4"> car <br>	    </form><script>$(function(){$('.formBuzType').change(function(){var value=$('.formBuzType').val()alert(value);});});	    </script>	   

  8. I am trying to attach a change event(usuing jquery) to a form radio button such that when the user selects either of the radio buttonsan alert message appear-it is for testing only. Here is the html:

    <form action="" method="post">  <input type="radio" class="formBuzType" name="buztype" value="5"> salon spa <br>  <input type="radio" class="formBuzType" name="buztype" value="4"> car <br>	    </form>

    and here is the js code:

    ('.formBuzType').change(function(){alert('hi');});

    On Google Dev Tools I get the following error message:Uncaught TypeError: Object .formBuzType has no method 'change' WHat the above means?

  9. The code you gave me does not work...it might be correct in itself but in the broader code context I think there is something wrong-see the whole code

    $(function() {    $('.error').hide();    $("#savepersonal").click(function() {	    event.preventDefault();		 $('.error').hide(); 	 	    var name = $("input#name").val(); 	    if (name == "") { 	  $("label#name_error").show(); 	  $("input#name").focus(); 	  return false;     }       var lastname = $("input#lastname").val(); 	    if (lastname == "") { 	  $("label#lastname_error").show(); 	  $("input#lastname").focus(); 	  return false;     }var form = document.getElementById('formBuzType');         // loop through the radio buttons to find which one is checked, then set var valueSelected to the value of the selected radio button         for(var i = 0; i < form.buztype.length; i++)  // buztype is the name of the radio buttons which is an array; ie buztype[0].value is 1, buztype[1].value is 2, buztype[2].value is 3 based on what you have above.         {                   if(form.buztype[i].checked)                  {                       var valueSelected = form.buztype[i].value;                  }           }    	 $.ajax({	  type: "POST",	  url: "testajax.php",	  data: {"name":name,"lastname":lastname,"btype":valueSelected}	 });      return false;   	       });     }); 

  10. I want to get the value of the radio button the user selected and send that with JSON to the server.I am not interested in learning the JSON syntax to use-more or less I know that. I want to know how to "grab" the value of the radio button selected by the user. THis is the HTML:

    <td> <label class="label" for="buztype">buztype</label><br></td>                                            <input type="radio" id="1"    name="buztype" value="1"> petshop<br>                      <input type="radio" id="2"     name="buztype" value="2"> salon spa <br>                      <input type="radio"  id="3"    name="buztype" value="3">medical <br>

    What js code will be needed to accomplish the task described above?

  11. If the code only tests $_GET['action'] == "complete" , if $_GET['action'] is not set, then the test will throw a warning.
    Υes, but I thought...that from the moment we have $_GET['action'] == "complete" we also have(by definition) $_GET['action']This is something I do not understand.
  12. var url = "autocomplete.php?action=complete&id=" + escape(completeField.value); There it is.
    Ok... :Bucktooth:Then...I do not understand...why he checks for isset($_GET['action']) AND isset($_GET['action']=='complete') also? He might check only for the 2nd.
  13. In the same tutorial there is a check if the user has filled in the input box:

    if(isset($_GET['action']) && $_GET['action'] == "complete")

    I do not understand the second part in the above line "$_GET['action'] == "complete"".I suppose it checks that the user has finished entering value in the input box.The question is where does this ''complete" comes from?Is it the one in the URL constructed in the doCompletion function?

  14. Yes you were right...but I need to make one more question.I know that data can be sent to the server with JSON...but in the example above(which is based on instructions in the jquery website)...nowhere is evident that data is being sent with JSON. How I could send the string above(which is user input) with JSON?

  15. I am trying to update the database using an ajax call but I cannot-the call itself though, is made...here is the js(jquery API) code:

    $(function() {    $('.error').hide();    $(".buttonaj").click(function() {		 $('.error').hide(); 	 	    var name = $("input#name").val(); 	    if (name == "") { 	  $("label#name_error").show(); 	  $("input#name").focus(); 	  return false;     }	 $.ajax({	  type: "POST",	  url: "testajax.php",	  data: name,	  success: function() {	    $('#personal').html("<div id='message'></div>");	    $('#message').html("<h2>Personal Data Updated!</h2>")	    .append("<p>We will be in touch soon.</p>")	    .hide()	    .fadeIn(1500);		  }	 });    return false;       });  });

    Here is the PHP code at testajax.php

      $conn = db_connect();		 $name=$_POST['name'];		  $result = $conn->query('update busines_users		    set name="'.$name.'"		    where crID="12"');		 		    if(!$result)			  { throw new Exception('Aδυναμία σύνδεσης με την βάση.');			  }

    db_connect is the function that makes the connection to the database.I was expecting that the var name in the js code(which contains the user input) would pass to the name variable in the php file but it does not.What might be the problem here?

  16. that is up for you application to handle. the response you generate from an AJAX request on the server side, should be meaningful enough for the Javascript to know what to do with it. If you are writing both, then it is entirely up to you how the two shall come to a mutual understanding.
    I still have to learn some things about frontend development...
  17. Ok, as you say we always do server-side validation.Suppose server validation finds error indeed in the user submitted data----how these errors going to be communicated back to the user(client mashine), with AJAX...?I am talking about the case where js is enabled of course.

  18. I know how to perform server validation but just recently a question popped in my mind(triggered by client-side validation ). Is the reason we perform server-side validationonly for the case where js is disabled or it can be useful also when js is enabled(acting as a double check).

  19. 1) gets the value of the users input and constructs a url...
    This is what I was expecting to hear and my main question was. I suppose completeField.value gets the user input.
×
×
  • Create New...