Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the If statement in actionscript 1

Status
Not open for further replies.

exit12

Technical User
Aug 19, 2003
44
GB
Hi
I have a button in my movie that when pressed submits 3 pieces of data, name, email and a message.

I would like to be able to check whether the user has actually entered anything and give an error message in a dynamic text box if they have left either input field blank.
Below is the action I have on my button so far. I'm unsure if I have to use If(), and where I would put it.

addButton.onRelease = function() {
myData = new LoadVars();
myData.name = name.text;
myData.email = email.text;
myData.msg = msg.text;

myData.sendAndLoad(" myData, "POST");
name.text = "";
email.text = "";
msg.text = "!Thank You for your message!";
function getVars() {
messages.htmltext = "";
myLoader = new LoadVars();
myloader.ran = random(999);
//again change the next line
myLoader.onLoad = function() {
for (i=0; i<this.n; i++) {
messages.htmltext += "Name: "+"<b>"+this["name"+i]+"</b>"+"<br>"+this["email"+i]+"<br><br>"+this["msg"+i]+"<br>"+" ----------------";
}
};
myLoader.sendAndLoad(" myLoader, "POST");
}
getVars();


};

If anyone could lend a hand I be very grateful!

Thanks
 
Code:
addButton.onRelease = function() {
	function checkVars(){
		if(name.text == ""){
			return false;
		}else if(email.text == ""){
			return false;
		}else if(msg.text == ""){
			return false;
		}else{
			return true;
		}
	}
	
	if (checkVars()) {
		myData = new LoadVars();
		myData.name = name.text;
		myData.email = email.text;
		myData.msg = msg.text;
		myData.sendAndLoad("[URL unfurl="true"]http://localhost/shoutphpsql/add.php",[/URL] myData, "POST");
		name.text = "";
		email.text = "";
		msg.text = "!Thank You for your message!";
		function getVars() {
			messages.htmltext = "";
			myLoader = new LoadVars();
			myloader.ran = random(999);
			//again change the next line
			myLoader.onLoad = function() {
				for (i=0; i<this.n; i++) {
					messages.htmltext += "Name: "+"<b>"+this["name"+i]+"</b>"+"<br>"+this["email"+i]+"<br><br>"+this["msg"+i]+"<br>"+" ----------------";
				}
			};
			myLoader.sendAndLoad("[URL unfurl="true"]http://localhost/shoutphpsql/loader.php",[/URL] myLoader, "POST");
		}
		getVars();
	}else{
		trace("Please fill out all required fields.");
	}
};

Also something to consider is that you should not use the word "name" as a text field as it is a reserved word and will cause you trouble in the long run... use something like "userName" instead.

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Hey thanks that worked a treat. Could you explain what the line
trace("pleas......."); does?, also how would I display a message within a blank text box on the stage? saying something like...Please fill out all details. etc..

Thanks again
 
In the flash testing environment it will cause the output box to open and be populated with the error message. To change it to a text box just add a blank dynamic textbox to the stage, give it an instanceName, and change that line of code to:

Code:
textBoxInstanceName.text = "Please fill...";


Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top