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 4 of 4

Thread: Posting

  1. #1
    New Coder
    Join Date
    Jun 2011
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Posting

    Ok, when I use this code:
    Code:
    <script type="text/javascript" src="../jquery-1.8.2.js"></script><script type="text/javascript">
    	
    
    
    
    $('#responseForm1').submit(function(){$('input[type=submit]', this);});
    function parseResponse () {
    	var code = $("#hiddenField2");
    	var n1 = $("#n1");
    	var url = "news_parse1.php";
    	
    		$.post(url,{  code: code.val(), n1: n1.val()} , function(data) {
    	
    		});
    		$.ajax({
    		type:"POST",
    		url:"news_load1.php",
    		data:"getNews=true",
    		success: function(r){
    			$("#newsContent").html(r)
    		var textbox = document.getElementById('code');
    
    	 			textbox.value ="";
    },
    		error: function(){
    			alert($("#hiddenField2"));
    			$("#error").text($("#hiddenField2")).fadeIn(300)
    		}
    	})
    
    
    	}
    	
    	</script>
        </head><body><form action="javascript:parseResponse();" id="responseForm1"> 
            <input type="hidden" name="hiddenField" id="hiddenField" value="" />
            <input type="text" name="hiddenField2" id="hiddenField2" class="hiddenField2" value="123" />
            <input type="hidden" name="hiddenField1" id="hiddenField1" value="" />
          <input type="submit" name="submit" class="submit" value="" style="left: 0px; background-color:lightgreen; height:70px; width:100px;">   </form>
    I get "[object Object]". I am not very good at javascript, seeing as that I can't seem to figure this out. can anyone help me figure this out? it is live at holidaypos.tk/test. thanks.
    Last edited by searls03; 11-18-2012 at 12:49 AM. Reason: code typo

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
    alert($("#hiddenField2"));
    will display [object Object] because that is what it is.. If you wish to display the content of the field use

    Code:
    alert($("#hiddenField2").val());
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    New Coder
    Join Date
    Jun 2011
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great! thanks!
    few more questions, what If i have more that one field and I use this javascript:
    Code:
    <script type="text/javascript">
    	
    
    
    
    $('.responseForm1').submit(function(){$('input[type=submit]', this);});
    function parseResponse () {
    	var code = $("#hiddenField2");
    	var n1 = $("#n1");
    	var url = "news_parse1.php";
    	
    		$.post(url,{  code: code.val(), n1: n1.val()} , function(data) {
    	
    		});
    		$.ajax({
    		type:"POST",
    		url:"news_load1.php",
    		data:"getNews=true",
    		success: function(r){
    			$("#newsContent").html(r)
    		var textbox = document.getElementById('code');
    
    	 			textbox.value ="";
    },
    		error: function(){
    alert($(".hiddenField2").val());			$("#error").text($("#hiddenField23")).fadeIn(300)
    		}
    	})
    
    
    	}
    	
    	</script>
    and lets say this repeats twice, with different php values cause of a loop:
    Code:
    <form action="javascript:parseResponse();" class="responseForm1"> 
            <input type="hidden" name="hiddenField" id="hiddenField" value="<?php echo $product; ?>" />
            <input type="text" name="hiddenField2" id="hiddenField2" class="hiddenField2" value="<?php echo $id; ?>" />
            <input type="hidden" name="hiddenField1" id="hiddenField1" value="<?php echo $price; ?>" />
          <input type="submit" name="submit" class="submit" value="<?php echo $final1; ?>" style="left: 0px; background-color:lightgreen; height:70px; width:100px;">   </form>
    <form action="javascript:parseResponse();" class="responseForm1"> 
            <input type="hidden" name="hiddenField" id="hiddenField" value="<?php echo $product; ?>" />
            <input type="text" name="hiddenField2" id="hiddenField2" class="hiddenField2" value="<?php echo $id; ?>" />
            <input type="hidden" name="hiddenField1" id="hiddenField1" value="<?php echo $price; ?>" />
          <input type="submit" name="submit" class="submit" value="<?php echo $final1; ?>" style="left: 0px; background-color:lightgreen; height:70px; width:100px;">   </form>
    How do I modify my JS code so that it will work for which ever form is submitted.

  • #4
    New Coder
    Join Date
    Jun 2011
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh and right now, I am just worried about the Error piece showing correctly, cause this is something that is easily displayed. I just make it purposefully show.


  •  

    Posting Permissions

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