473,471 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Javascript split function

20 New Member
Hi, i am currently having problem with the split function. Below are the code:

Expand|Select|Wrap|Line Numbers
  1. function callback_hello(str) {
  2.        var str_b4_split = (str);
  3.        var str_af_split = str_b4_split.split(" ");
  4.       document.write(str_af_split);
  5. }
  6.  
callback_hello will receive a return string value and store in str_b4_split.

I tried to display str_b4_split , and it is successful using document.write(str_b4_split).

However, when i tried to add in the split, i was unable to display any of it in IE7, and firefox 2.0. Firefox shown nothing, IE7 shown "Object doesn't support this property or method" in error msg.


May i know what is the reason behind this? thank you
Dec 26 '07 #1
4 4368
Ranjan kumar Barik
95 New Member
Hi, i am currently having problem with the split function. Below are the code:

Expand|Select|Wrap|Line Numbers
  1. function callback_hello(str) {
  2.        var str_b4_split = (str);
  3.        var str_af_split = str_b4_split.split(" ");
  4.       document.write(str_af_split);
  5. }
  6.  
callback_hello will receive a return string value and store in str_b4_split.

I tried to display str_b4_split , and it is successful using document.write(str_b4_split).

However, when i tried to add in the split, i was unable to display any of it in IE7, and firefox 2.0. Firefox shown nothing, IE7 shown "Object doesn't support this property or method" in error msg.


May i know what is the reason behind this? thank you
Hi,

I have tried your code in firefox 2.0 but it's working fine.
I donot have IE7 but Idonot think that will create any problem.
By the way just check if you have embeded the javascript codes inside script tags properly and also called it properly.

Happy Programming!
Dec 26 '07 #2
gits
5,390 Recognized Expert Moderator Expert
hi ...

please post more of your code especially where you call your function ... may be str is undefined at the moment where the function is called?

kind regards
Dec 26 '07 #3
DannyMc
20 New Member
Hi, I am using AjaxAgent from ajaxagent.org. I have modified the example code given in http://ajaxagent.org/doc.php . I will not attach agent.php in here(You will need it to run the code below).

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.   // server side function
  3.   function getdetail()
  4. {
  5. exec("ping www.google.com", $coutput);
  6. return $coutput;
  7. }
  8. ?>
  9.  
  10. <?php 
  11.   // STEP 1: INCLUDING AJAX AGENT FRAMEWORK/LIBRARY
  12.   include_once("agent.php");
  13. ?>
  14.  
  15. <html>
  16. <head>
  17. <title>My Ajax Agent Test Page</title>
  18. <?php
  19.   // STEP 2: INITIALIZING SERVER AGENT TO CREATE CLIENT AGENT
  20.   $agent->init(); 
  21. ?>
  22. </head>
  23. <body>
  24.   <script language="JavaScript">
  25.  
  26.     // client function  
  27.     function call_hello() {
  28.       // STEP 3: CALLING SERVER FUNCTION FROM CLIENT AGENT
  29.       agent.call('','getdetail','callback_hello');
  30.     }
  31.     // client callback function
  32.     function callback_hello(str) {
  33.        var myString = (str);
  34.       document.write(myString);
  35. }
  36.  
  37.  
  38.   </script>
  39. <p>testing</p>
  40. <a href="javascript:call_hello();">Test the hello function</a>
  41.  
  42. </body>
  43. </html>
  44.  
Here is the result i will get:
,Pinging www.l.google.com [72.14.253.99] with 32 bytes of data:,,Reply from 72.14.253.99: bytes=32 time=197ms TTL=236,Reply from 72.14.253.99: bytes=32 time=198ms TTL=236,Reply from 72.14.253.99: bytes=32 time=197ms TTL=236,Reply from 72.14.253.99: bytes=32 time=198ms TTL=236,,Ping statistics for 72.14.253.99:, Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),,Approximate round trip times in milli-seconds:, Minimum = 197ms, Maximum = 198ms, Average = 197ms


However, after i split the myString:
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.   // server side function
  3.   function getdetail()
  4. {
  5. exec("ping www.google.com", $coutput);
  6. return $coutput;
  7. }
  8. ?>
  9.  
  10. <?php 
  11.   // STEP 1: INCLUDING AJAX AGENT FRAMEWORK/LIBRARY
  12.   include_once("agent.php");
  13. ?>
  14.  
  15. <html>
  16. <head>
  17. <title>My Ajax Agent Test Page</title>
  18. <?php
  19.   // STEP 2: INITIALIZING SERVER AGENT TO CREATE CLIENT AGENT
  20.   $agent->init(); 
  21. ?>
  22. </head>
  23. <body>
  24.   <script language="JavaScript">
  25.  
  26.     // client function  
  27.     function call_hello() {
  28.       // STEP 3: CALLING SERVER FUNCTION FROM CLIENT AGENT
  29.       agent.call('','getdetail','callback_hello');
  30.     }
  31.     // client callback function
  32.     function callback_hello(str) {
  33.        var myString = (str);
  34.        var mySplitResult = myString.split(",");  //--------------->HERE
  35.       document.write(mySplitResult); // ------------------------------->HERE
  36. }
  37.  
  38.  
  39.   </script>
  40. <p>testing</p>
  41. <a href="javascript:call_hello();">Test the hello function</a>
  42.  
  43. </body>
  44. </html>
  45.  

I was unable to get anything. Is there anything wrong with the code?

I have even tried with var mySplitResult = myString.split("\\,"); and still not working. Please advice. thank you.
Dec 27 '07 #4
gits
5,390 Recognized Expert Moderator Expert
so i assume that:

Expand|Select|Wrap|Line Numbers
  1. ',Pinging www.l.google.com [72.14.253.99] with 32 bytes of data:,,Reply from 72.14.253.99: bytes=32 time=197ms TTL=236,Reply from 72.14.253.99: bytes=32 time=198ms TTL=236,Reply from 72.14.253.99: bytes=32 time=197ms TTL=236,Reply from 72.14.253.99: bytes=32 time=198ms TTL=236,,Ping statistics for 72.14.253.99:, Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),,Approximate round trip times in milli-seconds:, Minimum = 197ms, Maximum = 198ms, Average = 197ms'
is the result that you get as param str in your callback-function? could you alert it before the split-operation?

kind regards
Dec 27 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Arjen | last post by:
Hi All, What I want to is using a string as PATTERN in a split function. This makes it possible for me to change the PATTERN on one place in my script... For example: $separator = ";"; $line...
4
by: Varad | last post by:
I'm trying to break this html statement at the "<!---->" <br><a href='www.link1.com'>Link1</a><!----><br><a href='www.link2.com'>Link2</a><!----><br><a href='www.link3.com'>Link3</a><!----> ...
5
by: NewToThis | last post by:
I am trying to use the split function to bread up lines in a file I am reading from. Some lines are working just fine, but a couple of the lines don't split up the way I would have thought. ...
3
by: Reb | last post by:
Hi, I could split only by a character. How do i split by a string. How can i do something like this. e.g., somestring.Split("name"); Thanks Reb
7
by: Christine | last post by:
My code has a split function that should split the text file of numbers. I've run this in previous programs as it is here and it worked, but now it wont work for some reason and returns...
2
by: Elhanan | last post by:
hi all.. i have the following string: 200850625~01~464~^^200850625~01~464~^^200850625~01~908~^^ which i will need to turn to a mutli-dimentional string array i used result.Split(new...
5
by: sck10 | last post by:
Hello, I have a list of email addresses that I need to send email to from the website. I am trying to use the "Split" function to get all the To's and then use the uBound function for the...
1
by: John | last post by:
Hi I have written a Split function which in turn calls the standard string split function. Code is below; Function Split1(ByVal Expression As String, Optional ByVal Delimiter As String = " ",...
1
by: Mody Kurani | last post by:
Hello, Whats wrong in my Function? <html> <head> <script type="text/javascript"> function GetProvider { var fullemail = openinviter.email_box.value;
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.