Jump to content

My function() not accepting a string with characters and integers combined. Pls Help!


holsy
 Share

Recommended Posts

Hi Everyone...I have been stumped on a problem for 3 days and am going nutz here. I have a line of code writing a recordset value (<%Response.Write objRs("ItemID")%>) using asp vbscript. The value is a unique identifier string with letters and numbers combined. Everything works fine with a string with all Integers but will not work with a string with integers and letters combined. Here is the calling function.

<a href="java script:void(0);" onMouseOver="this.style.textDecoration='underline'" onMouseOut="this.style.textDecoration='none'" style="TEXT-DECORATION: none" onClick="message_box.show_message('Message box', 'DELETE ITEM ?', '[color="#FF0000"]<%Response.Write objRs("ItemID")%>[/color]' );"><b>Remove</b></a>

The string value is then passed to the show_message: function(title, body, strID), then the string value is sent to the: var button = '<input type="button" onclick="message_box.delete_record(' + strItemID + ');"value="Okay!" />'; The goal is to execute a href page redirection to delete a record when the user presses the OK button.I've tried everything in my limited javascript brain to make it work with a string with integers and letters combined but no luck however the code works with a string with integers only. it basically stalls at show_message: function(title, body, strID). I've tried converting the receiving argument (strID) to a String() but nothing. Does anyone have a solution or any suggestions? Thanks!!!Here is the Jquery modal message box javascript function:

<script language="JavaScript" type="text/JavaScript">var message_box = function() {	return {		show_message: function(title, body, strID)		{			var strItemID = strID;			var button = '<input type="button" onclick="message_box.delete_record(' + strItemID + ');"value="Okay!" />';			var button2 = '<input type="button" onclick="message_box.close_message();"value="No!" />';			if(jQuery('#message_box').html() === null)			{				var message = '<div id="message_box"><h1>' + title + '</h1>' + body + strItemID + '<br/>' + button + button2 +'</div>';				jQuery(document.body).append( message );				jQuery(document.body).append( '<div id="darkbg"></div>' );				jQuery('#darkbg').show();				jQuery('#darkbg').css('height', jQuery('html, body').height()); 				jQuery('#message_box').css('top', jQuery('html, body').scrollTop() + 200);				jQuery('#message_box').show('slow');			}			else			{				var message = '<h1>' + title + '</h1>' + body + strItemID + '<br/>' + button + button2;				jQuery('#darkbg').show();				jQuery('#darkbg').css('height', jQuery('html, body').height()); 				jQuery('#message_box').css('top', jQuery('html, body').scrollTop() + 200);				jQuery('#message_box').show('slow');				jQuery('#message_box').html( message );			}		},			close_message: function() {			jQuery('#message_box').hide('fast');			jQuery('#darkbg').hide();		},			delete_record: function(strItemID) {			jQuery('#message_box').hide('fast');			jQuery('#darkbg').hide();			window.location.href = 'blank.html?Action=Delete&Item=' + strItemID;					}	}}();</script>

Link to comment
Share on other sites

edit: nevermind, I think I misinterpreted the issue. First thing I should have asked for is are there any errors showing when you call message_box? What is the raw HTML output of this line

<a href="java script:void(0);" onMouseOver="this.style.textDecoration='underline'" onMouseOut="this.style.textDecoration='none'" style="TEXT-DECORATION: none" onClick="message_box.show_message('Message box', 'DELETE ITEM ?', '<%Response.Write objRs("ItemID")%>' );"><b>Remove</b></a>

when you view the source of the page?----I'm not sure, but I think the issue may he here?

var button = '<input type="button" onclick="message_box.delete_record(' + strItemID + ');"value="Okay!" />';

to me it looks like it would output as

<!-- where strItemId = "abc123" --><input type="button" onclick="message_box.delete_record(abc123);" value="Okay!" />

I believe you need it to quote the value of strItemId when creating the input element, like so:

var button = '<input type="button" onclick="message_box.delete_record(\'' + strItemID + '\');"value="Okay!" />';

so the output would look something like

<!-- where strItemId = "abc123" --><input type="button" onclick="message_box.delete_record('abc123');" value="Okay!" />

or else javascript is going to look for abc123 as a variable, not just an ordinary string

Edited by thescientist
Link to comment
Share on other sites

Thanks thescientist!!! Your suggestion: var button = '<input type="button" onclick="message_box.delete_record(\'' + strItemID + '\');"value="Okay!" />'; worked.It was being read as a variable rather than a string value. I had googled it for days but was unable to find info about using the "\". Thanks for your help.Cheers!

Edited by holsy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...