Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

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 08-04-2011, 07:23 AM   PM User | #16
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
I did ... one post ago ... you indeed have an XHTML doctype that's why document.forms["name"] will not work, but document.getElementById("formid") will as soon as your form element has the id="formid"
devnull69 is offline   Reply With Quote
Old 08-04-2011, 08:17 AM   PM User | #17
dev07
New Coder

 
Join Date: Aug 2011
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
dev07 is an unknown quantity at this point
Still failed to get the expected post submission action. Used the following code.

document.getElementById('form'+count_number).submit();

In form tried with both :


<form name="form<?php echo $j?>" id="form<?php echo $j?>" action="<?php echo $_SERVER['PHP_SELF']?>" method="post" onsubmit="contract(<?php echo $j?>);return false;">



<form name="form<?php echo $j?>" id="form<?php echo $j?>" action="#" method="post" onsubmit="contract(<?php echo $j?>);return false;">

Last edited by dev07; 08-04-2011 at 08:21 AM..
dev07 is offline   Reply With Quote
Old 08-04-2011, 06:09 PM   PM User | #18
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Ok, now I see the next flaw ... you should remove the onsubmit from the form and move it as onclick to the submit button

Otherwise you will always end up in running contract() again as soon as the form is being submitted programmatically.
devnull69 is offline   Reply With Quote
Old 08-05-2011, 07:04 AM   PM User | #19
dev07
New Coder

 
Join Date: Aug 2011
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
dev07 is an unknown quantity at this point
Well, i removed the onsubmit action from form tag. Added onclick function on submit button. But, i am having the following problems.

CASE 1) While using the code

<input type="submit" name="btn_submit" style="background: url(accept.jpg) no-repeat scroll center center transparent; cursor: pointer; border: 0pt none; width: 88px; height: 23px;" value="" onclick="contract(<?php echo $j?>);">

AND

if(parseInt(response, 10)==1)
{
if(confirm('Please confirm that this is a binding contract'))
{ document.getElementById('accept_offer'+count_number).submit();
}

}
else {
alert("Sorry, you are a little late. ");
}



==> The form always returns true and gets submitted and does post submission task without displaying the confirm message or alert message.



CASE 2) While using the code

<input type="submit" name="btn_submit" style="background: url(accept.jpg) no-repeat scroll center center transparent; cursor: pointer; border: 0pt none; width: 88px; height: 23px;" value="" onclick="contract(<?php echo $j?>);return false;">

AND

if(parseInt(response, 10)==1)
{
if(confirm('Please confirm that this is a binding contract'))
{ document.getElementById('accept_offer'+count_number).submit();
}

}
else {
alert("Sorry, you are a little late. ");
}


==>The form does not submits its data and also post submission task does not executes.


CASE 3) Removed return false from submit button and tried to use inside javascript condition [i.e return true if confirm else return false], but it returns the result of CASE 1.
dev07 is offline   Reply With Quote
Old 08-05-2011, 07:17 AM   PM User | #20
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
CASE 2 should be the correct one ... you should continue from there and debug

1. Is the function actually being called?
2. Does it start the Ajax request
3. Does the Ajax request return with the correct result
4. Does the confirm() come up
5. Finally: Does the .submit() actually do anything?

Right now, obviously it doesn't reach step 5 ... but you can only find out through debugging
devnull69 is offline   Reply With Quote
Old 08-05-2011, 07:45 AM   PM User | #21
dev07
New Coder

 
Join Date: Aug 2011
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
dev07 is an unknown quantity at this point
Quote:
Originally Posted by devnull69 View Post
CASE 2 should be the correct one ... you should continue from there and debug

1. Is the function actually being called?
2. Does it start the Ajax request
3. Does the Ajax request return with the correct result
4. Does the confirm() come up
5. Finally: Does the .submit() actually do anything?

Right now, obviously it doesn't reach step 5 ... but you can only find out through debugging

Answers to your questions.

1) Yes, the function has been called.

2) Ajax request started and getting correct result from AJAX request.

3) Confirm message is coming up.

4) Then if i press "OK", the page gets refreshed but no post submission task executes. If i press "Cancel", nothing happens.


I tried to debug and found the followings.

1) In a normal submission process [without using return false in onclick] the form gets submitted. And the url is:

http://abc.com/abc.php?InterestedUse...=&btn_submit=#


2) While using return false in onclick and after confirming "ok" , i found the following url

http://abc.com/abc.php?InterestedUse...=172&ItemId31=

where btn_submit= is missing.


I am processing the post submission query using the following code:


if(isset($_REQUEST['btn_submit']))
{
...
...
}


Now, as $_REQUEST['btn_submit'] is absent in the url, the page does not process post submission task.

I tried to modify the document.getElementById('accept_offer'+count_number).submit(); by document.getElementById('btn_submit').click(); but did not succeed. This time , the confirm message comes out whenever i am clicking on "OK".

Last edited by dev07; 08-05-2011 at 08:32 AM..
dev07 is offline   Reply With Quote
Old 08-05-2011, 08:57 AM   PM User | #22
dev07
New Coder

 
Join Date: Aug 2011
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
dev07 is an unknown quantity at this point
I got a solution but not sure whether i should use this or not.


1) I have added another submit button and made it hidden.

<input type="submit" name="Btn_Submit" id="Btn_Submit" style="background: url(accept.jpg) no-repeat scroll center center transparent; cursor: pointer; border: 0pt none; width: 88px; height: 23px;" value="" onclick="contract(<?php echo $j?>);return false;">

<input style="display:none" type="submit" name="btn_submit" id="btn_submit<?php echo $j;?>"></input>



2) Now on javascript function using this code.

if(confirm('Please confirm that this is a binding contract'))
{ document.getElementById('btn_submit'+count_number).click();
}



Using this i can perform the post submission task in Firefox. I will test other browser as well.

Please give me your suggestion.
dev07 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 05:17 PM.


Advertisement
Log in to turn off these ads.