Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-18-2012, 12:49 AM   PM User | #1
searls03
New Coder

 
Join Date: Jun 2011
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
searls03 is an unknown quantity at this point
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
searls03 is offline   Reply With Quote
Old 11-18-2012, 01:15 AM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
AndrewGSW is offline   Reply With Quote
Old 11-18-2012, 01:22 AM   PM User | #3
searls03
New Coder

 
Join Date: Jun 2011
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
searls03 is an unknown quantity at this point
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.
searls03 is offline   Reply With Quote
Old 11-18-2012, 01:23 AM   PM User | #4
searls03
New Coder

 
Join Date: Jun 2011
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
searls03 is an unknown quantity at this point
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.
searls03 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:07 AM.


Advertisement
Log in to turn off these ads.