Jump to content

[SOLVED] Javascript Form Submit


Niccaman

Recommended Posts

Javascript:

if (temp == 1)
				{
					document.abortForm.submit();
				}

 

Form:

<form name="abortForm" action="" method="post">
    <div id="postLeave" style="width:100%; text-align:center; display:none; height:0px;">
        <div style="width:100%;">
          <input type="hidden" name="thisOp" value="1">
          <input type="submit" name="submit" value="Confirm" class="output" style="width:50%;">
          <input type="button" value="Cancel" class="output" style="width:50%;" onclick="cancelLeave()">
        </div>
    </div>
</form>

 

 

I have tried variations of writing form submission in the javascript (that i know of), inluding:

"document.forms[0].submit();", and have also tried giving the form an action.

 

 

No JS errors reported with firebug.

I stuck an alert statement in the if statement, and i know it gets there.

 

So why does my form not submit? because of my hidden divs? i just dont understand.

Link to comment
Share on other sites

function refreshTranscript(num)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
	alert ("Browser does not support HTTP Request");
	return;
}
var url="/organised/transcript.php";
url=url+"?id=1&opid="+num;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function stateChanged8() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		var temp = xmlHttp.responseText;
		if (temp == 1)
		{
			document.forms[0].submit();
		}else
		{
			var before = document.getElementById('transcript').innerHTML.length;
			document.getElementById('transcript').innerHTML = temp;
			var after = document.getElementById('transcript').innerHTML.length;
			if (!(before == after))
			{
				scrollChat();
			}
			setTimeout("refreshTranscript("+num+");",10000);
		}
	}
};
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

 

.... its basically an ajax chat element. the part we are discussing is when the chat is closed, the php file will return 1 which is stored in 'temp'.

Link to comment
Share on other sites

Niccaman, posting "nothing happening" doesn't help us know what went wrong. Does the AJAX resolve? Are you getting the else case instead of the if case? If you do alert(temp), does it alert?

 

I assume nothing happening means your AJAX failed, meaning literally nothing happened.

Link to comment
Share on other sites

Lol no, as im sure i said earlier, i know the if statement is fulfilled as i tested it with an alert already.

 

The else part (actual chat feature) works perfectly.

 

I confirm that the if statement is fulfilled. When i say nothing happens i mean absolutly nothing happens. I have a firefox web developer toolbar which reports no errors of anykind including javascript.

 

The code gets to the submit code line, and im assuming it executes it successfully with zero effect.

Link to comment
Share on other sites

Yes, but requires some effort to fulfill the condition.

www.rogueagents.org

...you'll need 2 accounts fulfill the condition. firstly go to "Organised Ops", then create a lobby with this username: 'FestiveSix' pw: 'asd' (this player has enough game-money to do this). Then join the lobby with your account, and have festivesix abort the 'Op'. When the op is aborted and a user is still inside the lobby, the chat feature will return 'temp == 1', this will consequently submit the page to leave the lobby, in order to ultimately prevent 'ghost' messages in the database.

 

If you cant be bothered with all that i will understand ;)

Link to comment
Share on other sites

So if I got this right, the procedure is -

1. Log in as FestiveSix

2. Click 'Organised Ops' at left panel. (spelling error on organized)

3. Invite testing1 to say 'Intelligence Expert'.

4. Click Abort Operation button?

 

Do I do anything with the Chat button? Sorry, I just want to make sure. :)

Link to comment
Share on other sites

yes, but abort with lobby leader (festivesix) whilst having the lobby on screen for the other user (testing1).

 

the chat refresh does so every 10 seconds, alternatively, you can try and chat in order to activate the form submit. Both events will cause 'temp == 1'.

 

if you chat you will trigger 'function transcript(num)' with 'document.abortForm.submit();'

if you wait for refresh you will trigger 'function refreshTranscript(num)' with 'document.forms[0].submit();'

 

... (I left 2 different codes from 2 different events so that you can see both times fail).

 

remember, the condition will only be fulfilled if you do not navigate away from the page after aborting with the other user.

 

(Also, organised is the correct way to spell in the english dictionary - British)

Link to comment
Share on other sites

standard behaviour is for the else statement to always occur. Rather you missed the if part if anything. The if part is fulfilled when you abort the operation with the leader, whilst being in the lobby (the part with the chat box from the op you just aborted) with another user. IF the op has been removed from the database (s=effect of aborting) the other user isnt meant to be on the page, and the submit is a method of notifying the user. The if part is fulfilled in order to have this effect, though right now, nothing happens.

 

..basically, when you abort, the if statement is fulfilled with the OTHER user.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.