Just a quick question. I have a JS function that takes a parameter as input. If the passed value happens to be NULL, I want to handle it accordingly. However, my limited experience with JS is making it difficult for me to use the correct syntax. Here's what I have so far. Can you help me change the syntax? The function has more code besides this snippet, and it works fine when I don't check for NULL. The issue lies in the last line due to using a reserved word, but I'm unsure how to resolve it.
<script type="text/javascript">
//Pass UserName from text box on form to Ajax call
function CheckUserName(UserName_element) {
var UserName = try { UserName_element.value; } catch (e) { };
For those wondering: This is a JavaScript function inside a VBScript Sub (unfortunately, the entire site is built in classic ASP).
Sub UserNameValidation_Entry()
%>
<div id="username_validation" style="width:15px;position:relative;float:right;">
<img id="valid_UserName_image" src="<%=UrlForAsset("/images/tick.png")%>" border="0" style="display:none;" alt="User Name is Available."
title="User Name is Avaliable." />
<img id="invalid_UserName_image" src="<%=UrlForAsset("/images/icon_delete_x_sm.png")%>" border="0" style="display:none;" alt="User Name Already Exists."
title="User Name Already Exists." />
</div>
<script type="text/javascript">
//Pass UserName from text box on form to Ajax call
function CheckUserName(UserName_element) {
var UserName = UserName_element.value;
var UserName = try { UserName_element.value; } catch (e) { };
$j.ajax({
data: { action: 'CheckUserName', p_UserName: UserName },
type: 'GET',
url: 'page_logic/_check_username_ajax.asp',
success: function (result) {
//If user exists return X out, if not return green checkmark
if (result == "True") {
try { valid_UserName_image.style.display = "none"; } catch (e) { };
try { invalid_UserName_image.style.display = "inline"; } catch (e) { };
}
else {
try { valid_UserName_image.style.display = "inline"; } catch (e) { };
try { invalid_UserName_image.style.display = "none"; } catch (e) { };
}
}
}
);
//return false;
}
</script>
Here's where the function is called.
<tr class="required_field">
<td class="empty"></td>
<td><b>Username:</b></td>
<td class="label_value_separator"></td>
<td>
<input type='text' name="username" size="24" maxlength="50" value="<%=Session("s_username") %>" onblur="CheckUserName(this);">
<% Call UserNameValidation_Entry() %>
</tr>