Convert as2 to as3 - actionscript-3

I found a script for searching and selecting a specific text from a dynamic text box
But the problem is it is AS2
I started Flash by only studying AS3 so i have no idea on how to convert AS2 to AS3
Pls someone help me :)
finder.onRelease = function() {
Selection.setFocus("_root.textInstance");
var inputterString:String = _root.inputter
var inputLength:Number = inputterString.length;
textStart = textVar.indexOf(inputter, 0);
if (inputLength>0) {
textEnd = textStart+inputLength;
} else {
textEnd = 0;
}
if (textStart>=0) {
Selection.setSelection(textStart, textEnd);
} else {
Selection.setSelection(0, 0);
}
_root.textEnd = textEnd;
};
findNext.onRelease = function() {
Selection.setFocus("_root.textInstance");
var inputterString:String = _root.inputter;
var inputLength:Number = inputterString.length;
textStart = textVar.indexOf(inputter, _root.textEnd);
if (inputLength>0) {
textEnd = textStart+inputLength;
} else {
textEnd = 0;
}
if (textStart>=0) {
Selection.setSelection(textStart, textEnd);
} else {
Selection.setSelection(0, 0);
}
_root.textEnd = textEnd;
}

It's not as bad as you might think, but what are finder and findNext - buttons? These are callbacks which can be created by
finder.addEventListener(MouseEvent.MOUSE_UP, finderCallback);
// somewhere else in the code
private function finderCallback(e:MouseEvent):void {
// code here
// anything like _root.<varName> references something on the main file,
// so this just has to be something you can access in the funciton
}

OK, this should be it. I made some assumptions about root.textInstance and the buttons.
import flash.events.MouseEvent;
function onFinderClicked(event:MouseEvent):void{
stage.focus = root.textInstance;
root.textInstance.selectable = true;
var inputterString:String = root.inputter
var inputLength:Number = inputterString.length;
textStart = textVar.indexOf(inputter, 0);
if (inputLength>0) {
textEnd = textStart+inputLength;
} else {
textEnd = 0;
}
if (textStart>=0) {
root.textInstance.setSelection(textStart, textEnd);
} else {
root.textInstance.setSelection(0, 0);
}
root.textEnd = textEnd;
};
function onFindNextClicked(event:MouseEvent):void{
stage.focus = root.textInstance;
root.textInstance.selectable = true;
var inputterString:String = root.inputter;
var inputLength:Number = inputterString.length;
textStart = textVar.indexOf(inputter, root.textEnd);
if (inputLength>0) {
textEnd = textStart+inputLength;
} else {
textEnd = 0;
}
if (textStart>=0) {
root.textInstance.setSelection(textStart, textEnd);
} else {
root.textInstance.setSelection(0, 0);
}
root.textEnd = textEnd;
}
finder.addEventListener(MouseEvent.CLICK, onFinderClicked);
findNext.addEventListener(MouseEvent.CLICK, onFindNextClicked);

Related

How to stop item from going back to original place?

This is a drag and drop matching game, my question is how do I stop the items from going back to its original place when I matched it wrongly? I want the items to stay. Please explain in details for me, would appreciate it a lot.
right_mc.visible=false;
wrong_mc.visible=false;
var orig1X:Number=item1_mc.x;
var orig1Y:Number=item1_mc.y;
var orig2X:Number=item2_mc.x;
var orig2Y:Number=item2_mc.y;
var orig3X:Number=item3_mc.x;
var orig3Y:Number=item3_mc.y;
item1_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item1_mc.addEventListener(MouseEvent.MOUSE_UP, item1Release);
item2_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item2_mc.addEventListener(MouseEvent.MOUSE_UP, item2Release);
item3_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item3_mc.addEventListener(MouseEvent.MOUSE_UP, item3Release);
done_btn.addEventListener(MouseEvent.CLICK, checkAnswers);
reset_btn.addEventListener(MouseEvent.CLICK, reset);
item1_mc.buttonMode=true;
item2_mc.buttonMode=true;
item3_mc.buttonMode=true;
function dragTheObject(event:MouseEvent):void
{
var item:MovieClip=MovieClip(event.target);
item.startDrag();
var topPos:uint=this.numChildren-5;
this.setChildIndex(item, topPos);
}
function item1Release(event:MouseEvent):void
{
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (dropZone1_mc.hitTestPoint(item.x,item.y))
{
item.x=dropZone1_mc.x;
item.y=dropZone1_mc.y;
}
else
{
item.x=orig1X;
item.y=orig1Y;
}
}
function item2Release(event:MouseEvent):void
{
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (dropZone2_mc.hitTestPoint(item.x,item.y))
{
item.x=dropZone2_mc.x;
item.y=dropZone2_mc.y;
}
else
{
item.x=orig2X;
item.y=orig2Y;
}
}
function item3Release(event:MouseEvent):void
{
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (dropZone3_mc.hitTestPoint(item.x,item.y))
{
item.x=dropZone3_mc.x;
item.y=dropZone3_mc.y;
}
else
{
item.x=orig3X;
item.y=orig3Y;
}
}
function checkAnswers(event:MouseEvent):void
{
if (dropZone1_mc.hitTestPoint(item1_mc.x,item1_mc.y) &&
dropZone2_mc.hitTestPoint(item2_mc.x,item2_mc.y) &&
dropZone3_mc.hitTestPoint(item3_mc.x,item3_mc.y))
{
wrong_mc.visible = false;
right_mc.visible = true;
}
else
{
wrong_mc.visible = true;
right_mc.visible = false;
}
}
function reset(event:MouseEvent):void {
item1_mc.x=orig1X;
item1_mc.y=orig1Y;
item2_mc.x=orig2X;
item2_mc.y=orig2Y;
item3_mc.x=orig3X;
item3_mc.y=orig3Y;
right_mc.visible=false;
wrong_mc.visible=false;
}
function itemRelease(event:MouseEvent):void {
var thisItem:MovieClip = MovieClip(event.target);
thisItem.stopDrag();
if (dropZone1_mc.hitTestPoint(thisItem.x,thisItem.y))
{
thisItem.x = dropZone1_mc.x;
thisItem.y = dropZone1_mc.y;
}
else if (dropZone2_mc.hitTestPoint(thisItem.x,thisItem.y))
{
thisItem.x = dropZone2_mc.x;
thisItem.y = dropZone2_mc.y;
}
else if (dropZone3_mc.hitTestPoint(thisItem.x,thisItem.y))
{
thisItem.x = dropZone3_mc.x;
thisItem.y = dropZone3_mc.y;
}
else if (thisItem==item1_mc)
{
event.target.x = orig1X;
event.target.y = orig1Y;
}
else if (thisItem==item2_mc)
{
event.target.x = orig2X;
event.target.y = orig2Y;
}
else {
event.target.x = orig3X;
event.target.y = orig3Y;
}
}
You should remove the else conditions from each and every release functions. Update code is given below:
right_mc.visible=false;
wrong_mc.visible=false;
var orig1X:Number=item1_mc.x;
var orig1Y:Number=item1_mc.y;
var orig2X:Number=item2_mc.x;
var orig2Y:Number=item2_mc.y;
var orig3X:Number=item3_mc.x;
var orig3Y:Number=item3_mc.y;
item1_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item1_mc.addEventListener(MouseEvent.MOUSE_UP, item1Release);
item2_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item2_mc.addEventListener(MouseEvent.MOUSE_UP, item2Release);
item3_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item3_mc.addEventListener(MouseEvent.MOUSE_UP, item3Release);
done_btn.addEventListener(MouseEvent.CLICK, checkAnswers);
reset_btn.addEventListener(MouseEvent.CLICK, reset);
item1_mc.buttonMode=true;
item2_mc.buttonMode=true;
item3_mc.buttonMode=true;
function dragTheObject(event:MouseEvent):void
{
var item:MovieClip=MovieClip(event.target);
item.startDrag();
var topPos:uint=this.numChildren-5;
this.setChildIndex(item, topPos);
}
function item1Release(event:MouseEvent):void
{
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (dropZone1_mc.hitTestPoint(item.x,item.y))
{
item.x=dropZone1_mc.x;
item.y=dropZone1_mc.y;
}
}
function item2Release(event:MouseEvent):void
{
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (dropZone2_mc.hitTestPoint(item.x,item.y))
{
item.x=dropZone2_mc.x;
item.y=dropZone2_mc.y;
}
}
function item3Release(event:MouseEvent):void
{
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (dropZone3_mc.hitTestPoint(item.x,item.y))
{
item.x=dropZone3_mc.x;
item.y=dropZone3_mc.y;
}
}
function checkAnswers(event:MouseEvent):void
{
if (dropZone1_mc.hitTestPoint(item1_mc.x,item1_mc.y) &&
dropZone2_mc.hitTestPoint(item2_mc.x,item2_mc.y) &&
dropZone3_mc.hitTestPoint(item3_mc.x,item3_mc.y))
{
wrong_mc.visible = false;
right_mc.visible = true;
}
else
{
wrong_mc.visible = true;
right_mc.visible = false;
}
}
function reset(event:MouseEvent):void {
item1_mc.x=orig1X;
item1_mc.y=orig1Y;
item2_mc.x=orig2X;
item2_mc.y=orig2Y;
item3_mc.x=orig3X;
item3_mc.y=orig3Y;
right_mc.visible=false;
wrong_mc.visible=false;
}
Please let me know if you face any issue.

ArgumentError: Error #1063: Argument count mismatch on MethodInfo-152(). Expected 1, got 3

I'm sorry for asking, but I have been reading the other 1063 errors and I am not able to apply them to my issue. I am still working on deep diving in AS3 and I get distracted with other work things, when I get back to it, I feel like a new issue comes up.
I am not sure why this isn't working, would greatly appreciate some guidance:
import flash.events.MouseEvent;
stop();
showNextButton(false);
var gift1_var:Number = 0;
var correct_new3:correct_q8 = new correct_q8;
var incorrect_new3:incorrect_q8 = new incorrect_q8;
var incorrect_new4:incorrect_q8 = new incorrect_q8;
var correct_new4:correct_q8 = new correct_q8;
var choices:Array = [
{
button: return_btn,
feedback_mc: correct_new3,
is_correct: true
},
{
button: give_btn,
feedback_mc: incorrect_new3,
is_correct: false
},
{
button: drink_btn,
feedback_mc: incorrect_new4,
is_correct: false
},
{
button: donate_btn,
feedback_mc: correct_new4,
is_correct: true
}
];
for (var i:int = 0; i < choices.length; i ++) {
var choice:Object = choices[i];
choice.button.addEventListener(MouseEvent.CLICK, onClick);
choice.button.buttonMode = true;
choice.button.obj = choice;
}
var num_selected:int = 0;
function onClick (evt:MouseEvent=null):void {
var btn:MovieClip = MovieClip(evt.currentTarget);
var choice:Object = btn.obj;
addChild(choice.feedback_mc);
choice.feedback_mc.x = btn.x;
choice.feedback_mc.y = btn.y;
if (choice.is_correct) {
gift1_var += 1;
}
addToSelected();
}
function addToSelected(evt:MouseEvent=null):void {
num_selected += 1;
if (num_selected === 2) {
showNextButton(true);
showButtons(false);
//trace("this worked");
}
}
function showNextButton (is_visible:Boolean):void {
MovieClip(root).next_mc.visible = is_visible;
}
function showButtons (is_visible:Boolean):void {
choices.forEach (function (choice:Object):void {
choice.button.visible = is_visible;
});
}
Oh, I figured it out, it is the 2 other arguments I am missing in the forEach
I added i:int, arr:Array into that location and it works. Sorry to waste anyone's time that read through this.
function showButtons (is_visible:Boolean):void {
choices.forEach (function (choice:Object, i:int, arr:Array):void {
choice.button.visible = is_visible;
});
}

Calculated Field in Custom CRM 4.0 Form

The onload event is firing and I am not getting any erroors, but the calculated field is not refreshing?
It should be doing the calculation from the function FWeightedValue().
Here is the code, any help would be appreciated.
frmOnLoad();
onLoad = false;
}
catch(e)
{ alert(e.message); }
}//End of if condition
}//End of function
/* Declare Variables */
var onLoad = true;
var sGlobalVar = '';
function frmOnLoad()
{ ResizeScreen();
AddLogoToFormTitle(160, "/CRM4Legal/_imgs/reznick_small.gif");
fldMerge('name');
fldMerge('customerid');
fldMerge('rg_officeid');
fldStatus();
fldGSMC();
FWeightedValue();
frmTabs();
frmNav();
frmIFrames();
if ($("rg_gsmc" ) != null) $("rg_gsmc" ).onclick = fldGSMC;
}
function FWeightedValue()
{ with ( crmForm.all )
var EstRev = crmForm.getAttribute("estimatedvalue").getValue();
var RiskWeight = Xrm.Page.getAttribute("cpdc_riskweight").getValue();
var RiskPercent = RiskWeight / 100;
Xrm.Page.data.entity.attributes.get("cpdc_riskweightedvalue").setValue(RiskWeightValue);
sectionDisplay( true, cpdc_riskweightedvalue);
}
FWeightedValue.NullCheck = function (value)
{
if (value == null) {
return 0.0;
} else {
return value;
}
}
}
function fldStatus()
{ with ( crmForm.all )
{ if ( statuscode.SelectedText == 'Won' || statuscode.SelectedText == 'Lost' )
{ crmForm.SetFieldReqLevel("rg_winlossreason", 1);
sectionDisplay( false, rg_winlossreason );
}
else
{ crmForm.SetFieldReqLevel("rg_winlossreason", 0);
rg_winlossreason.DataValue = null;
sectionDisplay( true, rg_winlossreason );
}
}
}
function fldGSMC()
{ with ( crmForm.all )
{ sectionDisplay( !rg_gsmc.DataValue, rg_contractnumber );
crmForm.SetFieldReqLevel("rg_contracttype", ( rg_gsmc.DataValue ? 1 : 0 ));
}
}
function fldMerge(fld)
{ if ( fld == null ) { return; }
var cell = $(fld + '_d');
if ( cell == null ) { return; }
var row = cell.parentNode;
if ( row == null ) { return; }
cell.colSpan = 3;
row.removeChild(cell.nextSibling);
row.removeChild(cell.nextSibling);
}
function frmTabs()
{ tab('Hidden', 'hidden');
}
function frmNav()
{ navHide ('nav_rg_opportunity_rg_opportunitypracticearea');
navHide ('nav_rg_opportunity_rg_opportunityservicearea');
navHide ('nav_rg_opportunity_rg_engagementteam');
navHide ('nav_rg_opportunity_rg_opportunityteam');
navHide ('navProducts');
navHide ('navQuotes');
navHide ('navOrders');
navHide ('navInvoices');
navHide ('navComp');
navHide ('_NA_SFA');}
function frmIFrames()
{ /* Engagement Team */
var n2nPA = new N2NViewer('IFRAME_EngagementTeam');
/* Set the role order - use iedevtoolber for exact parameters */
n2nPA.RoleOrder = 1;
/* assing the relationship name (without the "area" word) */
n2nPA.TabsetId = "rg_opportunity_rg_engagementteam";
n2nPA.Load();
/* Opportunity Team */
var n2nPA = new N2NViewer('IFRAME_OpportunityTeam');
n2nPA.RoleOrder = 1;
n2nPA.TabsetId = "rg_opportunity_rg_opportunityteam";
n2nPA.Load();
/* Practice Areas */
var n2nPA = new N2NViewer('IFRAME_PracticeAreas');
n2nPA.RoleOrder = 1;
n2nPA.TabsetId = "rg_opportunity_rg_opportunitypracticearea";
n2nPA.Load();
/* Service Areas */
var n2nService = new N2NViewer('IFRAME_Services');
n2nService.RoleOrder = 1;
n2nService.TabsetId = "rg_opportunity_rg_opportunityservicearea";
n2nService.Load();
}
function $(name)
{ return document.getElementById(name);
}
function navHide (name)
{ if ($(name) != null) { $(name).style.display = "none"; }
}
function tab ( tabName, tabVisibility )
{ tabVisibility = ( tabVisibility == "visible" ? "" : "none" );
var _tabs = crmForm.getElementsByTagName("li");
for (var i = 0; i < _tabs.length; i++)
{ var _tab = _tabs[i];
if ( _tab.innerText == tabName )
{ _tab.style.display = tabVisibility;
break;
}
}
}
function sectionDisplay(vis, sec)
{ sec.parentElement.parentElement.parentElement.style.display = ((vis) ? 'none' : 'block');
}
function ResizeScreen()
{ var aH = screen.availHeight;
var aW = screen.availWidth;
var top = 0;
var left = 0;
if ( aW >= 1124 && aH >= 800)
{ var aH = (aH > 800 ? 800 : 768);
var aW = 1124;
var top = (screen.availHeight - aH) / 2;
var left = (screen.availWidth - aW) / 2;
}
// aH = (crmForm.FormType == frmType.Create ? 295 : aH);
window.moveTo(left, top);
window.resizeTo(aW, aH);
}
function N2NViewer(iframeId)
{ if (!document.all[iframeId])
{ alert(iframeId + " is missing!");
return;
}
var viewer = this;
var _locAssocObj = null;
viewer.IFRAME = document.all[iframeId];
viewer.RoleOrder;
viewer.TabsetId;
viewer.Load = function()
{ if (crmForm.ObjectId != null)
{ /* Construct a valid N2N IFRAME url */
viewer.IFRAME.src = "areas.aspx?oId=" + crmForm.ObjectId + "&oType=" + crmForm.ObjectTypeCode + "&security=" + crmFormSubmit.crmFormSubmitSecurity.value + "&roleOrd=" + viewer.RoleOrder + "&tabSet=" + viewer.TabsetId;
viewer.IFRAME.onreadystatechange = viewer.StateChanged;
}
else
{ viewer.IFRAME.src = "about:blank";
}
}
viewer.StateChanged = function()
{ if (viewer.IFRAME.readyState != 'complete')
{ return;
}
var iframeDoc = viewer.IFRAME.contentWindow.document;
/* Reomve scrolling space */
iframeDoc.body.scroll = "no";
/* Remove crmGrid Default padding */
iframeDoc.body.childNodes[0].rows[0].cells[0].style.padding = 0;
/* Save MS locAssocObj */
_locAssocObj = locAssocObj;
/* Override MS locAssocObj */
locAssocObj = viewer.locAssocObj;
}
viewer.locAssocObj = function(iType , sSubType, sAssociationName, iRoleOrdinal)
{ /* Open the Dialog */
_locAssocObj(iType , sSubType, sAssociationName, iRoleOrdinal);
/* Refresh only if our iframe contains the correnct tabset name */
if (sAssociationName == viewer.TabsetId)
{ viewer.IFRAME.contentWindow.document.all.crmGrid.Refresh();
}
}
}
function AddLogoToFormTitle(logoWidth, logoUrl)
{ var formTitleTable = null;
var tables = document.getElementsByTagName("table");
for(var i = 0; i < tables.length; i++)
{ var className = tables[i].className;
if (className && className.indexOf("ms-crm-Form-Title") == 0)
{ formTitleTable = tables[i];
break;
}
}
if (formTitleTable)
{ var newCell = formTitleTable.rows[0].insertCell(2);
newCell.width = logoWidth;
newCell.vAlign = "middle";
newCell.innerHTML = '<img src="'+logoUrl+'" border="0" align="right" />';
}
}
function UnUsed()
{
if(false)
{
try
{
You mixed CRM 4.0 and CRM 2011 SDKs. No wonder nothing is working!
Below is what should be written if your target platform is CRM 4.0
function FWeightedValue()
{
var EstRev = crmForm.estimatedvalue.DataValue;
var RiskWeight = crmForm.cpdc_riskweight.DataValue;
var RiskPercent = RiskWeight / 100;
crmForm.cpdc_riskweightedvalue.DataValue = RiskWeightValue;
// second parameter is sec ??? or field
sectionDisplay( true, crmForm.cpdc_riskweightedvalue);
}
Did you try Force Submit?
Xrm.Page.getAttribute(fieldName).setSubmitMode("always");

Cant stop this Timer

Create button and give name "b".
create dynamic text and give name "tampil".
Run it... Click on b button to run the timer, and click again to stop(but error).
The following script is a piece of my project that I modified.
My question is, how do I stop the timer?
import flash.events.MouseEvent;
var xx:Number = 1;
var waktux:Timer;
var i1:Number = 1;
var ab:Number = 1;
var lantaii:String = "lg";
b.addEventListener(MouseEvent.CLICK, stopp);
function stopp(e:MouseEvent)
{
waktu(0,0,ab);
if (ab==1)
{
ab = 0;
}
else
{
ab = 1;
}
}
function waktu(e, d, cx)
{
var waktux:Timer;
var waktuy:Timer;
function sayHello(f:TimerEvent):void
{
tampil.text = String(e);
e = e + 1;
}
function sayHellow(e:TimerEvent):void
{
tampil.text = String(d);
d = d + 1;
}
function sayHello2(f:TimerEvent):void
{
tampil.text = String(e);
e = e + 1;
}
if (cx==1)
{
if (lantaii == "lg")
{
naek();
}
else
{
waktuy = new Timer(400,10);
waktuy.addEventListener(TimerEvent.TIMER, sayHellow);
waktuy.start();
waktuy.addEventListener(TimerEvent.TIMER_COMPLETE, naek2);
}
function naek()
{
waktux = new Timer(400,10);
waktux.addEventListener(TimerEvent.TIMER, sayHello);
waktux.start();
}
function naek2(s:TimerEvent):void
{
waktux = new Timer(400,10);
waktux.addEventListener(TimerEvent.TIMER, sayHello2);
waktux.start();
}
}
else
{
trace("nih masuk");
waktux.stop();
waktux.reset();
waktuy.reset();
waktux.removeEventListener(TimerEvent.TIMER, sayHello);
waktux.removeEventListener(TimerEvent.TIMER, sayHello2);
waktuy.removeEventListener(TimerEvent.TIMER, sayHellow);
waktuy.removeEventListener(TimerEvent.TIMER_COMPLETE, naek2);
}
}
I think you redefine waktux one in global scope and other in waktu function.
delete one of these lines
import flash.events.MouseEvent;
var xx:Number = 1;
var waktux:Timer; //<--------------------------- HERE
var i1:Number = 1;
var ab:Number = 1;
var lantaii:String = "lg";
function waktu(e, d, cx)
{
var waktux:Timer; //<--------------------------- HERE
var waktuy:Timer;
function sayHello(f:TimerEvent):void
{
tampil.text = String(e);
e = e + 1;
}
function sayHellow(e:TimerEvent):void
{
tampil.text = String(d);
d = d + 1;
}
function sayHello2(f:TimerEvent):void
{
tampil.text = String(e);
e = e + 1;
}
if (cx==1)
{
if (lantaii == "lg")
{
naek();
}
else
{
waktuy = new Timer(400,10);
waktuy.addEventListener(TimerEvent.TIMER, sayHellow);
waktuy.start();
waktuy.addEventListener(TimerEvent.TIMER_COMPLETE, naek2);
}
function naek()
{
waktux = new Timer(400,10);
waktux.addEventListener(TimerEvent.TIMER, sayHello);
waktux.start();
}
function naek2(s:TimerEvent):void
{
waktux = new Timer(400,10);
waktux.addEventListener(TimerEvent.TIMER, sayHello2);
waktux.start();
}
}
else
{
trace("nih masuk");
waktux.stop();
waktux.reset();
waktuy.reset();
waktux.removeEventListener(TimerEvent.TIMER, sayHello);
waktux.removeEventListener(TimerEvent.TIMER, sayHello2);
waktuy.removeEventListener(TimerEvent.TIMER, sayHellow);
waktuy.removeEventListener(TimerEvent.TIMER_COMPLETE, naek2);
}
}
and just for fun
function stopp(e:MouseEvent)
{
waktu(0,0,ab);
ab = !ab;
}

firebug saying not a function

<script type = "text/javascript">
var First_Array = new Array();
function reset_Form2() {document.extraInfo.reset();}
function showList1() {document.getElementById("favSports").style.visibility="visible";}
function showList2() {document.getElementById("favSubjects").style.visibility="visible";}
function hideProceed() {document.getElementById('proceed').style.visibility='hidden';}
function proceedToSecond ()
{
document.getElementById("div1").style.visibility="hidden";
document.getElementById("div2").style.visibility="visible";
document.getElementById("favSports").style.visibility="hidden";
document.getElementById("favSubjects").style.visibility="hidden";
}
function backToFirst () {
document.getElementById("div1").style.visibility="visible";
document.getElementById("div2").style.visibility="hidden";
document.getElementById("favSports").style.visibility="visible";
document.getElementById("favSubjects").style.visibility="visible";
}
function reset_Form(){
document.personalInfo.reset();
document.getElementById("favSports").style.visibility="hidden";
document.getElementById("favSubjects").style.visibility="hidden";
}
function isValidName(firstStr) {
var firstPat = /^([a-zA-Z]+)$/;
var matchArray = firstStr.match(firstPat);
if (matchArray == null) {
alert("That's a weird name, try again");
return false;
}
return true;
}
function isValidZip(zipStr) {
var zipPat =/[0-9]{5}/;
var matchArray = zipStr.match(zipPat);
if(matchArray == null) {
alert("Zip is not in valid format");
return false;
}
return true;
}
function isValidApt(aptStr) {
var aptPat = /[\d]/;
var matchArray = aptStr.match(aptPat);
if(matchArray == null) {
if (aptStr=="") {
return true;
}
alert("Apt is not proper format");
return false;
}
return true;
}
function isValidDate(dateStr) {
//requires 4 digit year:
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
var matchArray = dateStr.match(datePat);
if (matchArray == null) {
alert("Date is not in a valid format.");
return false;
}
return true;
}
function checkRadioFirst() {
var rb = document.personalInfo.salutation;
for(var i=0;i<rb.length;i++) {
if(rb[i].checked) {
return true;
}
}
alert("Please specify a salutation");
return false;
}
function checkCheckFirst() {
var rb = document.personalInfo.operatingSystems;
for(var i=0;i<rb.length;i++) {
if(rb[i].checked) {
return true;
}
}
alert("Please specify an operating system") ;
return false;
}
function checkSelectFirst() {
if ( document.personalInfo.sports.selectedIndex == -1)
{
alert ( "Please select a sport" );
return false;
}
return true;
}
function checkRadioSecond() {
var rb = document.extraInfo.referral;
for(var i=0;i<rb.length;i++) {
if(rb[i].checked) {
return true;
}
}
alert("Please select form of referral");
return false;
}
function checkCheckSecond() {
var rb = document.extraInfo.officeSupplies;
for(var i=0;i<rb.length;i++) {
if(rb[i].checked) {
return true;
}
}
alert("Please select an office supply option");
return false;
}
function checkSelectSecond() {
if ( document.extraInfo.colorPick.selectedIndex == 0 ) {
alert ( "Please select a favorite color" );
return false;
}
return true;
}
function check_Form(){
var retvalue = isValidDate(document.personalInfo.date.value);
if(retvalue) {
retvalue = isValidZip(document.personalInfo.zipCode.value);
if(retvalue) {
retvalue = isValidName(document.personalInfo.nameFirst.value);
if(retvalue) {
retvalue = checkRadioFirst();
if(retvalue) {
retvalue = checkCheckFirst();
if(retvalue) {
retvalue = checkSelectFirst();
if(retvalue) {
retvalue = isValidApt(document.personalInfo.aptNum.value);
if(retvalue){
document.getElementById('proceed').style.visibility='visible';
var rb = document.personalInfo.salutation;
for(var i=0;i<rb.length;i++) {
if(rb[i].checked) {
var salForm = rb[i].value;
}
}
var SportsOptions = "";
for(var j=0;j<document.personalInfo.sports.length;j++){
if ( document.personalInfo.sports.options[j].selected){
SportsOptions += document.personalInfo.sports.options[j].value + " ";
}
}
var SubjectsOptions= "";
for(var k=0;k<document.personalInfo.subjects.length;k++){
if ( document.personalInfo.subjects.options[k].selected){
SubjectsOptions += document.personalInfo.subjects.options[k].value + " ";
}
}
var osBox = document.personalInfo.operatingSystems;
var OSOptions = "";
for(var y=0;y<osBox.length;y++) {
if(osBox[y].checked) {
OSOptions += osBox[y].value + " ";
}
}
First_Array[0] = salForm;
First_Array[1] = document.personalInfo.nameFirst.value;
First_Array[2] = document.personalInfo.nameMiddle.value;
First_Array[3] = document.personalInfo.nameLast.value;
First_Array[4] = document.personalInfo.address.value;
First_Array[5] = document.personalInfo.aptNum.value;
First_Array[6] = document.personalInfo.city.value;
for(var l=0; l<document.personalInfo.state.length; l++) {
if (document.personalInfo.state.options[l].selected) {
First_Array[7] = document.personalInfo.state[l].value;
}
}
First_Array[8] = document.personalInfo.zipCode.value;
First_Array[9] = document.personalInfo.date.value;
First_Array[10] = document.personalInfo.phone.value;
First_Array[11] = SportsOptions;
First_Array[12] = SubjectsOptions;
First_Array[13] = OSOptions;
alert("Everything looks good.");
document.getElementById('validityButton').style.visibility='hidden';
}
}
}
}
}
}
}
}
/*function formAction2() {
var retvalue;
retvalue = checkRadioSecond();
if(!retvalue) {
return retvalue;
}
retvalue = checkCheckSecond();
if(!retvalue) {
return retvalue;
}
return checkSelectSecond() ;
} */
</script>
This is just a sample of the code, there are alot more functions, but I thought the error might be related to surrounding code. I have absolutely no idea why, as I know all the surrounding functions execute, and First_Array is populated.
However when I click the Proceed to Second button, the onclick attribute does not execute because Firebug says proceedToSecond is not a function
button code:
<input type="button" id="proceed" name="proceedToSecond" onclick="proceedToSecond();" value="Proceed to second form">
I had the same problem, and it's because you have a form with the same name as your function. JavaScript doesn't seem to be able to distinguish between the two, so you get the "not a function" error.
Maybe there is an error in your Javascript before that snippet given by you. If so, the rest will not be parsed by Firefox and then your function will not be defined.
The problem was resolved by changing proceedToSecond() to doIt() in both the call and the function name. I have no idea why
Hmm... I always used javascript:function_name() instead of function_name() because a few times the javascript didn't run. The name tag for the html snippet might have to be changed to a slightly different name because javascript might be getting it mixed up. Can you show us the entire javascript file because there may be a mistake/syntax error somewhere at the bottom/top.
It works on my computer, Firefox 3.5.5, Firebug 1.4.3, when inserting your code into an empty html document (<html><head/><body> code </body></html>)
Maybe there is another bug somewhere in your DOM, or in some of your other functions?
Could you possibly paste the entire source here, or maybe on a pastebin site?