/    Sign up×
Community /Pin to ProfileBookmark

Script needs alert call to function…

Hi all, I’ve trying to run a webpage with the following code:

[code]
<head>
<import json.js>
<script type=”text/javascript”>
function keypressed() {
var selectElement = $(‘id_community’);
var communityName = $(‘communityTextBox’);
var request = new Ajax.Request(‘../’ + communityName.value + ‘/schoolList/’,
{
method:’get’,
onSuccess: function(transport){
var response = transport.responseText || “no response text”;
var myObject = eval(‘(‘+ response +’)’)
for(var loop = selectElement.options.length; loop >= 0; loop–) {
selectElement.options[loop] = null;
}
for(var i=0; i<=myObject.number; i++) {
var newElement = document.createElement(‘option’);
newElement.text = myObject.colors[i];
newElement.value = myObject.values[i];
//alert(newElement.value);
selectElement.options.add(newElement);
}
},
onFailure: function(){ return }
});
}

</script>
[/code]

and a form that looks like this:

[code]
<form action=”.” method=”post” enctype=”multipart/form-data”>
<table>
<tr><th><label for=”id_community”>Community:</label></th><td></td><td>

<input type=”textarea” id=”communityTextBox” onKeyUp=”javascript:keypressed()” onFocus=”if(this.value==’School Name…’)this.value=”” value=”School Name…” style=”width:235px”>
</td></tr>

<tr><td></td><td></td><td><select name=”community” id=”id_community” style=”width:235px”>

</select><br /></td></tr>

<tr><th><label for=”id_newUsername”>Username:</label></th><td></td><td><input id=”id_newUsername” type=”text” name=”newUsername” maxlength=”30″ style=”width:235px”/></td></tr>
<tr><th><label for=”id_email”>Email:</label></th><td></td><td><input type=”text” name=”email” id=”id_email” style=”width:235px” /></td></tr>
<tr><th><label for=”id_Password2″>Password:</label></th><td></td><td><input id=”id_Password2″ type=”password” name=”Password2″ maxlength=”16″ style=”width:235px” /></td></tr>
<tr><th><label for=”id_Password1″>Password (Again):</label></th><td></td><td><input id=”id_Password1″ type=”password” name=”Password1″ maxlength=”16″ style=”width:235px” /></td></tr>
</table><br />
<div id=”tableSubmit”>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=”submit” name=”submit” value=”Cancel” />

&nbsp;&nbsp;&nbsp;&nbsp;<input type=”submit” name=”submit” value=”Continue”/>
</div>
</form>
[/code]

when i fill in the page and hit submit, the form refuses to properly submit and i get error messages telling me that none of the elements have been submitted.
HOWEVER, when i uncomment the line //alert(newElement.value); everything works as it should! Does anyone have any clue as to why this strange behavior is going on?
I’ve tried it both in google chrome and in firefox to the same end, and the firefox javascript error checker doesn’t flash any errors or warnings or anything.

THanks a lot!!
-Robert

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @robokin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...